A service port identification method and system
By classifying network data packets and identifying service port one-to-many learning modules, combined with confidence calculation, the problem of inaccurate service port identification in the existing technology is solved, and the identification efficiency and accuracy are improved, especially in UDP and TCP. Long connection communication in progress.
Patent Information
- Application Number
- CN202110891310.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-08-04
- Publication Date
- 2024-08-23
- Estimated Expiration
- 2041-08-04
AI Technical Summary
Existing service port identification methods have low accuracy in network data analysis. It is especially difficult to identify service ports for UDP communication and TCP long connection communication, and the identification is inaccurate when the source port and destination port meet the same conditions.
By classifying network data packets, using the service port one-to-many learning sub-module to identify the service port, and calculating the confidence, judging the consistency between the service port and the third service port, and selecting the port with high confidence as the output result, the problem is solved Accuracy of service port identification.
It improves the efficiency and accuracy of service port identification, especially in UDP communication and TCP long connection communication, which greatly improves the accuracy of identification and solves the problem of inaccurate identification of source port and destination port under the same conditions.
Smart Images

Figure CN113542035B
Abstract
Description
Technical Field
[0001] The present invention relates to the field of data transmission, and in particular to a service port identification method and system. Background Art
[0002] When conducting network data analysis, it is usually necessary to identify which services exist in the network and the direction of communication, that is, who is the client and who is the server. Accurate server identification is a very important part of network data analysis. However, in existing related technologies, service ports are basically identified through well-known ports, network data packet types, port sizes, the number of port appearances, etc., and the identification accuracy is not high. In addition, the service port identification method is too single and inaccurate. Summary of the invention
[0003] The technical problem to be solved by the present invention is to provide a service port identification method and system.
[0004] The technical solution of the present invention to solve the above technical problem is as follows: a service port identification method, comprising:
[0005] Step 1, classifying the protocols obtained from the network data packets, and then identifying and processing the network data packets corresponding to the classified protocol types, obtaining the corresponding service ports and calculating the confidence of the service ports;
[0006] Step 2, inputting the network data packet into the service port one-to-many learning submodule, identifying a third service port through the service port one-to-many learning submodule, and calculating a third confidence of the third service port;
[0007] Step 3, determine whether the service port is consistent with the third service port. If they are consistent, output the judgment result to complete the identification. If they are inconsistent, select the service port with higher confidence among the confidence level and the third confidence level as the output result to complete the identification.
[0008] The beneficial effects of the present invention are as follows: by classifying network data packets and then performing service port identification, the identification efficiency can be made faster and more accurate, especially the one-to-many learning submodule of the service port solves the problem that the service ports of UDP communication and TCP long connection communication are difficult to identify; in addition, by calculating the confidence, the problem of inaccurate identification when the source port and the destination port meet the same conditions is solved, which greatly improves the accuracy of service port identification.
[0009] Based on the above technical solution, the present invention can also be improved as follows.
[0010] Further, the step 1 specifically includes:
[0011] If the protocol type is the TCP protocol type, identifying and processing the network data packet, obtaining a first service port and calculating a first confidence level of the first service port;
[0012] If the protocol type is the UDP protocol type, the network data packet is identified and processed to obtain a second service port and calculate a second confidence level of the second service port.
[0013] Further, the step 3 specifically includes:
[0014] When the service port is the first service port, determine whether the first service port is consistent with the third service port, if they are consistent, output the determination result to complete the identification, if they are inconsistent, select the service port with higher confidence among the first confidence and the third confidence as the output result to complete the identification; or
[0015] When the service port is the second service port, determine whether the second service port is consistent with the third service port. If they are consistent, output the judgment result to complete the identification. If they are inconsistent, select the service port with higher confidence among the second confidence and the third confidence as the output result to complete the identification.
[0016] Further, the third service port is identified by the service port one-to-many learning submodule as:
[0017] Based on the statistical dictionary, a first corresponding number is counted, the first corresponding number is the number of ports that have been connected to the source port in the network data packet, and a second corresponding number is counted, the second corresponding number is the number of ports that have been connected to the destination port in the network data packet, and it is determined whether the first corresponding number and the second corresponding number are greater than a threshold value. If only the first corresponding number is greater than the threshold value, the source port is output as a third service port; if only the second corresponding number is greater than the threshold value, the destination port is output as a third service port; if both the first corresponding number and the second corresponding number are not greater than the threshold value, the third service port is not output; if both the first corresponding number and the second corresponding number are greater than the threshold value, the first corresponding number and the second corresponding number are compared. If the first corresponding number is larger, the source port is output as the third service port, if the second corresponding number is larger, the destination port is output as the third service port, and if the first corresponding number and the second corresponding number are the same, the destination port is output as the third service port, wherein the statistical dictionary is composed of key-value pairs, wherein the key is the source port and the destination port in each network data packet, and the value is the number of ports that the source port or the destination port has been connected.
[0018] Further, if the protocol type is the TCP protocol type, the network data packet is identified and processed, and the first service port is obtained as follows:
[0019] Inputting the identified TCP network data packet into the TCP communication service port identification submodule, the TCP communication service port identification submodule determines the type of the network data packet;
[0020] If the type is determined to be a SYN packet, the destination port in the network packet is the first service port;
[0021] If the type is determined to be a SYNACK data packet, the source port in the network data is the first service port;
[0022] If the type is judged to be neither a SYN packet nor a SYNACK packet, and the source port and the destination port in the network packet are not equal, then the source port and the destination port in the network packet are searched in the TCP service port table. If only the source port is searched, the source port is the first service port. If only the destination port is searched, the destination port is the first service port. If both the source port and the destination port are searched, the confidences of the source port and the destination port are compared. The port with a higher confidence is the first service port. If the confidences are consistent, the port with a smaller port number between the source port and the destination port is the first service port.
[0023] If the type is judged to be neither a SYN packet nor a SYNACK packet, and the source port and the destination port in the network packet are equal, then the source IP address and the destination IP address in the network packet are compared. If the source IP address is larger, the source port is the first service port; if the destination IP address is larger, the destination port is the first service port.
[0024] Further, if the protocol type is the UDP protocol type, the network data packet is identified and processed, and the second service port is obtained as follows:
[0025] The identified UDP network data packet is input into the UDP communication service port identification submodule, and the UDP communication service port identification submodule determines whether the lowest bit of the first byte of the destination MAC address is 1;
[0026] If it is 1, the communication is multicast communication, and the destination port in the network data packet is the second service port;
[0027] If it is not 1, and the source port and the destination port in the network data packet are not equal, then the source port and the destination port in the network data packet are searched in the UDP service port table. If only the source port is searched, the source port is the second service port. If only the destination port is searched, the destination port is the second service port. If both the source port and the destination port are searched, the confidences of the source port and the destination port are compared. The port with a higher confidence is the second service port. If the confidences are consistent, the port with a smaller port number between the source port and the destination port is the second service port.
[0028] If it is not 1, and the source port and destination port in the network data packet are equal, then compare the source IP address and destination IP address in the network data packet. If the source IP address is larger, the source port is the first service port; if the destination IP address is larger, the destination port is the first service port.
[0029] Further, the confidence of the service port is calculated as follows:
[0030] The confidence calculation submodule is called to calculate the confidence of the service port.
[0031] Further, the calling confidence calculation submodule calculates the confidence of the service port specifically as follows:
[0032] Calculate the dimension confidence of different dimensions of the service port, and add the dimension confidence of each dimension according to the weight corresponding to each dimension to obtain the total confidence. When the total confidence reaches the second threshold, the confidence calculation for the port is no longer performed;
[0033] Among them, the calculation formula of dimension confidence c is as follows:
[0034] c=100×(1-0.4 x )×w
[0035] Wherein, x is the number of times the recognition condition is met and when x reaches the first threshold, it will no longer increase, and w is the weight.
[0036] Furthermore, it also includes:
[0037] After the identification is completed, the storage database is searched to see whether there is a historical service port that is opposite to the client IP address of the identified service port and the server IP address of the identified service port. If not, the identified service port is stored in the storage database. If so, it is determined whether the confidence of the identified service port is less than the confidence of the historical service port. If so, the identified service port is determined to be wrong and not stored. If so, the historical service port is determined to be wrong, the relevant data of the historical service port is deleted from the storage database, and the identified service port is stored in the storage database.
[0038] Another technical solution of the present invention to solve the above technical problem is as follows: a service port identification system, comprising:
[0039] A port acquisition module, used to classify the protocols obtained from the network data packets, and then identify and process the network data packets corresponding to the classified protocol types, obtain the corresponding service ports and calculate the confidence of the service ports;
[0040] A port learning module, used for inputting the network data packet into a service port one-to-many learning submodule, identifying a third service port through the service port one-to-many learning submodule, and calculating a third confidence of the third service port;
[0041] The port identification module is used to determine whether the service port is consistent with the third service port. If they are consistent, the judgment result is output to complete the identification. If they are inconsistent, the service port with higher confidence among the confidence level and the third confidence level is selected as the output result to complete the identification.
[0042] The beneficial effects of the present invention are as follows: by classifying network data packets and then performing service port identification, the identification efficiency can be made faster and more accurate, especially the one-to-many learning submodule of the service port solves the problem that the service ports of UDP communication and TCP long connection communication are difficult to identify; in addition, by calculating the confidence, the problem of inaccurate identification when the source port and the destination port meet the same conditions is solved, which greatly improves the accuracy of service port identification.
[0043] Furthermore, the port acquisition module is specifically used for:
[0044] If the protocol type is the TCP protocol type, identifying and processing the network data packet, obtaining a first service port and calculating a first confidence level of the first service port;
[0045] If the protocol type is the UDP protocol type, the network data packet is identified and processed to obtain a second service port and calculate a second confidence level of the second service port.
[0046] Further, the port identification module is specifically used for:
[0047] When the service port is the first service port, determine whether the first service port is consistent with the third service port, if they are consistent, output the determination result to complete the identification, if they are inconsistent, select the service port with higher confidence among the first confidence and the third confidence as the output result to complete the identification; or
[0048] When the service port is the second service port, determine whether the second service port is consistent with the third service port. If they are consistent, output the judgment result to complete the identification. If they are inconsistent, select the service port with higher confidence among the second confidence and the third confidence as the output result to complete the identification.
[0049] Further, the third service port is identified by the service port one-to-many learning submodule as:
[0050] Based on the statistical dictionary, a first corresponding number is counted, the first corresponding number is the number of ports that have been connected to the source port in the network data packet, and a second corresponding number is counted, the second corresponding number is the number of ports that have been connected to the destination port in the network data packet, and it is determined whether the first corresponding number and the second corresponding number are greater than a threshold value. If only the first corresponding number is greater than the threshold value, the source port is output as a third service port; if only the second corresponding number is greater than the threshold value, the destination port is output as a third service port; if both the first corresponding number and the second corresponding number are not greater than the threshold value, the third service port is not output; if both the first corresponding number and the second corresponding number are greater than the threshold value, the first corresponding number and the second corresponding number are compared. If the first corresponding number is larger, the source port is output as the third service port, if the second corresponding number is larger, the destination port is output as the third service port, and if the first corresponding number and the second corresponding number are the same, the destination port is output as the third service port, wherein the statistical dictionary is composed of key-value pairs, wherein the key is the source port and the destination port in each network data packet, and the value is the number of ports that the source port or the destination port has been connected.
[0051] Further, if the protocol type is the TCP protocol type, the network data packet is identified and processed, and the first service port is obtained as follows:
[0052] Inputting the identified TCP network data packet into the TCP communication service port identification submodule, the TCP communication service port identification submodule determines the type of the network data packet;
[0053] If the type is determined to be a SYN packet, the destination port in the network packet is the first service port;
[0054] If the type is determined to be a SYNACK data packet, the source port in the network data is the first service port;
[0055] If the type is judged to be neither a SYN packet nor a SYNACK packet, and the source port and the destination port in the network packet are not equal, then the source port and the destination port in the network packet are searched in the TCP service port table. If only the source port is searched, the source port is the first service port. If only the destination port is searched, the destination port is the first service port. If both the source port and the destination port are searched, the confidences of the source port and the destination port are compared. The port with a higher confidence is the first service port. If the confidences are consistent, the port with a smaller port number between the source port and the destination port is the first service port.
[0056] If the type is judged to be neither a SYN packet nor a SYNACK packet, and the source port and the destination port in the network packet are equal, then the source IP address and the destination IP address in the network packet are compared. If the source IP address is larger, the source port is the first service port; if the destination IP address is larger, the destination port is the first service port.
[0057] Further, if the protocol type is the UDP protocol type, the network data packet is identified and processed, and the second service port is obtained as follows:
[0058] Input the identified UDP network data packet into the UDP communication service port identification submodule, and the UDP communication service port identification submodule determines whether the lowest bit of the first byte of the destination MAC address is 1;
[0059] If it is 1, the communication is multicast communication, and the destination port in the network data packet is the second service port;
[0060] If it is not 1, and the source port and the destination port in the network data packet are not equal, then the source port and the destination port in the network data packet are searched in the UDP service port table. If only the source port is searched, the source port is the second service port. If only the destination port is searched, the destination port is the second service port. If both the source port and the destination port are searched, the confidences of the source port and the destination port are compared. The port with a higher confidence is the second service port. If the confidences are consistent, the port with a smaller port number between the source port and the destination port is the second service port.
[0061] If it is not 1, and the source port and destination port in the network data packet are equal, then compare the source IP address and destination IP address in the network data packet. If the source IP address is larger, the source port is the first service port; if the destination IP address is larger, the destination port is the first service port.
[0062] Further, the confidence of the service port is calculated as follows:
[0063] The confidence calculation submodule is called to calculate the confidence of the service port.
[0064] Further, the calling confidence calculation submodule calculates the confidence of the service port specifically as follows:
[0065] Calculate the dimension confidence of different dimensions of the service port, and add the dimension confidence of each dimension according to the weight corresponding to each dimension to obtain the total confidence. When the total confidence reaches the second threshold, the confidence calculation for the port is no longer performed;
[0066] Among them, the calculation formula of dimension confidence c is as follows:
[0067] c=100×(1-0.4 x )×w
[0068] Wherein, x is the number of times the recognition condition is met and when x reaches the first threshold, it will no longer increase, and w is the weight.
[0069] Furthermore, it also includes:
[0070] The error self-check module is used to search in the storage database whether there is a historical service port that is opposite to the client IP address of the identified service port and the server IP address of the identified service port after completing the identification. If not, the identified service port is stored in the storage database. If so, it is determined whether the confidence of the identified service port is less than the confidence of the historical service port. If so, it is determined that the identified service port is wrong and is not stored. If so, it is determined that the historical service port is wrong, and the relevant data of the historical service port is deleted in the storage database, and the identified service port is stored in the storage database.
[0071] Another technical solution of the present invention to solve the above technical problem is as follows: a storage medium, wherein instructions are stored in the storage medium, and when a computer reads the instructions, the computer executes a service port identification method as described in any one of the above items.
[0072] The beneficial effects of the present invention are as follows: by classifying network data packets and then performing service port identification, the identification efficiency can be made faster and more accurate, especially the one-to-many learning submodule of the service port solves the problem that the service ports of UDP communication and TCP long connection communication are difficult to identify; in addition, by calculating the confidence, the problem of inaccurate identification when the source port and the destination port meet the same conditions is solved, which greatly improves the accuracy of service port identification.
[0073] Another technical solution of the present invention to solve the above technical problem is as follows: an electronic device comprises a memory, a processor and a program stored in the memory and running on the processor, wherein when the processor executes the program, a service port identification method as described in any one of the above items is implemented.
[0074] The beneficial effects of the present invention are as follows: by classifying network data packets and then performing service port identification, the identification efficiency can be made faster and more accurate, especially the one-to-many learning submodule of the service port solves the problem that the service ports of UDP communication and TCP long connection communication are difficult to identify; in addition, by calculating the confidence, the problem of inaccurate identification when the source port and the destination port meet the same conditions is solved, which greatly improves the accuracy of service port identification. BRIEF DESCRIPTION OF THE DRAWINGS
[0075] Figure 1 A flow chart of a method for identifying a service port according to an embodiment of the present invention;
[0076] Figure 2 A structural framework diagram provided for an embodiment of a service port identification system of the present invention. DETAILED DESCRIPTION
[0077] The principles and features of the present invention are described below. The examples given are only used to explain the present invention and are not used to limit the scope of the present invention.
[0078] like Figure 1 As shown, the present invention provides a service port identification method, comprising:
[0079] Step 1, classifying the protocols obtained from the network data packets, and then identifying and processing the network data packets corresponding to the classified protocol types, obtaining the corresponding service ports and calculating the confidence of the service ports;
[0080] Step 2, inputting the network data packet into the service port one-to-many learning submodule, identifying a third service port through the service port one-to-many learning submodule, and calculating a third confidence of the third service port;
[0081] Step 3, determine whether the service port is consistent with the third service port. If they are consistent, output the judgment result to complete the identification. If they are inconsistent, select the service port with higher confidence among the confidence level and the third confidence level as the output result to complete the identification.
[0082] In the present invention, step 1, step 2 and step 3 are not used as conditions to limit the sequence of the method, and can be adjusted before or after according to the actual situation of the specific embodiment. For example, after determining the protocol type, different types are input into different processing modules for processing, and the calculation of the confidence of the corresponding service port and the third confidence can actually be performed before or after according to the situation.
[0083] In some possible implementations, by classifying network data packets and then identifying service ports, the identification efficiency can be faster and more accurate. In particular, the one-to-many learning submodule of the service port solves the problem that the service ports of UDP communication and TCP long connection communication are difficult to identify. In addition, by calculating the confidence level, the problem of inaccurate identification when the source port and the destination port meet the same conditions is solved, which greatly improves the accuracy of service port identification.
[0084] It should be noted that after receiving the network data packet, the network data packet is parsed to obtain the protocol, data packet type, port information, MAC address information and IP address information, wherein the port information includes the source port and the destination port, and the corresponding IP address includes the source IP address corresponding to the source port and the destination IP address corresponding to the destination port. First, the protocol is classified, and the TCP protocol enters the TCP communication service port identification submodule, and the UDP protocol enters the UDP communication service port identification submodule. In the above two modules, the service port will be identified according to the information such as the data packet type, and the confidence calculation submodule will be called to record the confidence of the service port; then the communication will enter the service port one-to-many learning submodule to learn the service port, and the confidence calculation submodule will be called to record the confidence of the service port; compare the confidence of the service port identified by the UDP service port identification submodule with the confidence of the service port learned by the service port one-to-many learning module, or the confidence of the service port identified by the TCP service port identification submodule and the confidence of the service port learned by the service port one-to-many learning module, and the one with a high confidence is considered to be the service port, and the IP address corresponding to the port is the server. In addition, the confidence level may be calculated using conventional existing calculation methods or by calculating confidence levels of different dimensions and superimposing the confidence levels to perform more accurate confidence level calculations. The superposition algorithm may be understood by referring to Example 2.
[0085] Preferably, in any of the above embodiments, step 1 specifically includes:
[0086] If the protocol type is the TCP protocol type, identifying and processing the network data packet, obtaining a first service port and calculating a first confidence level of the first service port;
[0087] If the protocol type is the UDP protocol type, the network data packet is identified and processed to obtain a second service port and calculate a second confidence level of the second service port.
[0088] Preferably, in any of the above embodiments, step 3 specifically includes:
[0089] When the service port is the first service port, determine whether the first service port is consistent with the third service port, if they are consistent, output the determination result to complete the identification, if they are inconsistent, select the service port with higher confidence among the first confidence and the third confidence as the output result to complete the identification; or
[0090] When the service port is the second service port, determine whether the second service port is consistent with the third service port. If they are consistent, output the judgment result to complete the identification. If they are inconsistent, select the service port with higher confidence among the second confidence and the third confidence as the output result to complete the identification.
[0091] Preferably, in any of the above embodiments, the third service port identified by the service port one-to-many learning submodule is specifically:
[0092] Based on the statistical dictionary, a first corresponding number is counted, the first corresponding number is the number of ports that have been connected to the source port in the network data packet, and a second corresponding number is counted, the second corresponding number is the number of ports that have been connected to the destination port in the network data packet, and it is determined whether the first corresponding number and the second corresponding number are greater than a threshold value. If only the first corresponding number is greater than the threshold value, the source port is output as a third service port; if only the second corresponding number is greater than the threshold value, the destination port is output as a third service port; if both the first corresponding number and the second corresponding number are not greater than the threshold value, the third service port is not output; if both the first corresponding number and the second corresponding number are greater than the threshold value, the first corresponding number and the second corresponding number are compared. If the first corresponding number is larger, the source port is output as the third service port, if the second corresponding number is larger, the destination port is output as the third service port, and if the first corresponding number and the second corresponding number are the same, the destination port is output as the third service port, wherein the statistical dictionary is composed of key-value pairs, wherein the key is the source port and the destination port in each network data packet, and the value is the number of ports that the source port or the destination port has been connected.
[0093] It should be noted that the one-to-many learning submodule of the service port: the one-to-many relationship means that if a port has been connected to three or more ports, it is considered that this port may be a service port. The source port and destination port in each network packet are saved in the port statistics dictionary respectively, and the storage format is {port number: {ports: [connected port 1, connected port 2, ...], timestamp: last updated time}}. The port statistics dictionary is stored in the memory to prevent excessive memory usage. After the port is learned, the relevant records in the dictionary need to be deleted in time. Not only the record of the port itself, but also all related records that have connected to this port should be deleted, and a protection mechanism should be set. When the record is greater than the threshold, the earliest record is deleted. The port statistics dictionaries of TCP and UDP are independent to prevent mutual influence.
[0094] Preferably, in any of the above embodiments, if the protocol type is a TCP protocol type, the network data packet is identified and processed to obtain the first service port specifically as:
[0095] Inputting the identified TCP network data packet into the TCP communication service port identification submodule, the TCP communication service port identification submodule determines the type of the network data packet;
[0096] If the type is determined to be a SYN packet, the destination port in the network packet is the first service port;
[0097] If the type is determined to be a SYNACK data packet, the source port in the network data is the first service port;
[0098] If the type is judged to be neither a SYN packet nor a SYNACK packet, and the source port and the destination port in the network packet are not equal, then the source port and the destination port in the network packet are searched in the TCP service port table. If only the source port is searched, the source port is the first service port. If only the destination port is searched, the destination port is the first service port. If both the source port and the destination port are searched, the confidences of the source port and the destination port are compared. The port with a higher confidence is the first service port. If the confidences are consistent, the port with a smaller port number between the source port and the destination port is the first service port.
[0099] If the type is judged to be neither a SYN packet nor a SYNACK packet, and the source port and the destination port in the network packet are equal, then the source IP address and the destination IP address in the network packet are compared. If the source IP address is larger, the source port is the first service port; if the destination IP address is larger, the destination port is the first service port.
[0100] It should be noted that the TCP communication service port identification submodule: first determine the data packet type, if it is a SYN packet, the destination port is the service port, the destination IP is the server, if it is a SYNACK packet, the source port is the service port, the source IP is the server; for communications that are neither SYN packets nor SYNACK packets, if the source port and destination port are not equal, the source port and destination port are matched in the TCP service port table respectively, that is, the TCP service port table will preset some well-known ports, and the matching is to see whether the source port and destination port of this communication are in the TCP service port table. If only one is matched, the matched port is the service port, and the corresponding IP is the server; if both are matched, compare the confidence of the two ports, the port with higher confidence is the service port, and the corresponding IP is the server; if the confidence is the same, the port with smaller confidence is the service port, and the corresponding IP is the server. If the source port and destination port are the same, only match once in the service port table, the IP address with larger value is the server, and the corresponding port is the service port; if the source port and destination port are not in the TCP service port table, compare the source port and destination port, the port with smaller value is the service port, and the corresponding IP is the server. If the source port and destination port are the same, compare the IP addresses, the IP address with larger value is the server, and the corresponding port is the service port; finally, call the confidence calculation submodule to calculate the confidence of the service port.
[0101] Preferably, in any of the above embodiments, if the protocol type is a UDP protocol type, the network data packet is identified and processed to obtain the second service port specifically as:
[0102] Input the identified UDP network data packet into the UDP communication service port identification submodule, and the UDP communication service port identification submodule determines whether the lowest bit of the first byte of the destination MAC address is 1;
[0103] If it is 1, the communication is multicast communication, and the destination port in the network data packet is the second service port;
[0104] If it is not 1, and the source port and the destination port in the network data packet are not equal, then the source port and the destination port in the network data packet are searched in the UDP service port table. If only the source port is searched, the source port is the second service port. If only the destination port is searched, the destination port is the second service port. If both the source port and the destination port are searched, the confidences of the source port and the destination port are compared. The port with a higher confidence is the second service port. If the confidences are consistent, the port with a smaller port number between the source port and the destination port is the second service port.
[0105] If it is not 1, and the source port and destination port in the network data packet are equal, then compare the source IP address and destination IP address in the network data packet. If the source IP address is larger, the source port is the first service port; if the destination IP address is larger, the destination port is the first service port.
[0106] It should be noted that the UDP communication service port identification submodule: first determine whether the lowest bit of the first byte of the destination MAC address is 1. If it is 1, it means that the communication is multicast communication, and the destination port is the service port; if it is not multicast communication, if the source port and the destination port are not equal, match the source port and the destination port in the UDP service port table respectively. If only one is matched, the matched port is the service port, and the corresponding IP is the server; if both are matched, compare the total confidence of the two ports, the port with higher confidence is the service port, and the corresponding IP is the service end; if the confidence is the same, the port with a smaller one is the service port, and the corresponding IP is the server. If the source port and the destination port are the same, only one match is made in the service port table. The one with a larger IP address is the server, and the corresponding port is the service port. If neither the source port nor the destination port is in the TCP service port table, compare the size of the source port and the destination port. The one with a smaller port is the service port, and the corresponding IP is the server. If the source port and the destination port are the same, compare the IP addresses. The one with a larger IP address is the server, and the corresponding port is the service port. Finally, call the confidence calculation submodule to calculate the confidence of the service port.
[0107] Preferably, in any of the above embodiments, the confidence of the service port is calculated as follows:
[0108] The confidence calculation submodule is called to calculate the confidence of the service port.
[0109] Preferably, in any of the above embodiments, the calling of the confidence calculation submodule to calculate the confidence of the service port is specifically:
[0110] Calculate the dimension confidence of different dimensions of the service port, and add the dimension confidence of each dimension according to the weight corresponding to each dimension to obtain the total confidence. When the total confidence reaches the second threshold, the confidence calculation for the port is no longer performed;
[0111] Among them, the calculation formula of dimension confidence c is as follows:
[0112] c=100×(1-0.4 x )×w
[0113] Wherein, x is the number of times the recognition condition is met and when x reaches the first threshold, it will no longer increase, and w is the weight.
[0114] Embodiment 1, confidence calculation submodule: There are multiple dimensions for service port identification, but each dimension has a different influence on the service port confidence, that is, the weight is different. Finally, the total confidence is obtained by adding up the confidence of each dimension. The dimensions of service port identification and the weight of each dimension are shown in Table 1 and Table 2:
[0115] Table 1
[0116]
[0117] Table 2
[0118]
[0119] The calculation formula of dimension confidence c is as follows:
[0120] c=100×(1-0.4 x )×w
[0121] x represents the number of times the condition is met, W represents the weight, and C represents the confidence. The final confidence is C1+C2+C3..., with a maximum of 100 points. The confidence of the preset well-known service port is manually set. If it is not set, it defaults to 0. The initial values of the confidence of other items are all 0. When the corresponding identification condition is met, one will be added to the count, that is, x+1 in the formula. The communication between the same host (source IP and destination IP are the same) is only added once. As x increases, the confidence will become higher and higher. The part in brackets in the formula is a function that approaches 1 infinitely from 0. Therefore, each confidence is always less than 100*W, and the part in brackets will grow slower and slower as x increases. In order to prevent the program from calculating all the time, when the x of a certain identification dimension reaches a certain threshold, the identification dimension will no longer be accumulated, and when the overall confidence of a port is greater than a certain threshold, the port is considered to be credible and no items will be calculated.
[0122] Preferably, in any of the above embodiments, it further comprises:
[0123] After the identification is completed, the storage database is searched to see whether there is a historical service port that is opposite to the client IP address of the identified service port and the server IP address of the identified service port. If not, the identified service port is stored in the storage database. If so, it is determined whether the confidence of the identified service port is less than the confidence of the historical service port. If so, the identified service port is determined to be wrong and not stored. If so, the historical service port is determined to be wrong, the relevant data of the historical service port is deleted from the storage database, and the identified service port is stored in the storage database.
[0124] It should be noted that sometimes service port identification may be wrong. For example, if a TCP connection is established successfully before packet capture for service port identification, the SYN or SYNACK packet of this connection cannot be captured at this time. If the service port used by the connection has not been recorded in the service port table, the service port can only be identified by port size. However, the service port identified by port size may be wrong. In this case, an error correction mechanism is needed to correct it. Each time a service port is identified, the source IP, destination IP, service port and client port of this connection will be recorded. The record format is shown in Table 3:
[0125] Table 3
[0126] connect Client IP Client port Server IP Server port Remark A 1.1.1.1 10001 1.1.1.2 10000 Identifying Errors B 1.1.1.1 10001 1.1.1.2 9000 Identifying Errors C 1.1.1.2 8000 1.1.1.1 10001 Correct identification
[0127] Each time a new record is added, the existing records will be searched for data that is opposite to the client IP and server IP of the current record. If the client port in these data is equal to the service port of the new record and the confidence of the service port is less than the confidence of the service port of the new record, it is considered that there is an incorrectly identified service port in the existing record and the incorrectly identified service port is deleted; if the service port in these data is equal to the client port of the new record and the confidence of the service port is greater than the confidence of the service port of the new record, it is considered that the service port of the new record is incorrectly identified and the incorrectly identified service port is deleted. The opposite data refers to the opposite server and client of the two sessions. The client IP of session B is equal to the server IP of session A, and the server IP of session B is equal to the client IP of session A. For example, the client IP of session A is 1.1.1.1 and the server IP is 1.1.1.2, and the client IP of session B is 1.1.1.2 and the server IP is 1.1.1.1.
[0128] In the above embodiments, although the steps are numbered S1, S2, etc., these are only specific embodiments given in the present application. Those skilled in the art may adjust the execution order of S1, S2, etc. according to actual conditions, which is also within the scope of protection of the present invention. It can be understood that in some embodiments, some or all of the above embodiments may be included.
[0129] like Figure 2 As shown, a service port identification system includes:
[0130] The port acquisition module 100 is used to classify the protocols obtained from the network data packets, and then identify and process the network data packets corresponding to the classified protocol types, obtain the corresponding service ports and calculate the confidence of the service ports;
[0131] The port learning module 200 is used to input the network data packet into the service port one-to-many learning submodule, identify and obtain a third service port through the service port one-to-many learning submodule, and calculate a third confidence of the third service port;
[0132] The port identification module 300 is used to determine whether the service port is consistent with the third service port. If they are consistent, the judgment result is output to complete the identification. If they are inconsistent, the service port with higher confidence in the confidence and the third confidence is selected as the output result to complete the identification.
[0133] In some possible implementations, by classifying network data packets and then identifying service ports, the identification efficiency can be faster and more accurate. In particular, the one-to-many learning submodule of the service port solves the problem that the service ports of UDP communication and TCP long connection communication are difficult to identify. In addition, by calculating the confidence level, the problem of inaccurate identification when the source port and the destination port meet the same conditions is solved, which greatly improves the accuracy of service port identification.
[0134] Preferably, in any of the above embodiments, the port acquisition module 100 is specifically used for:
[0135] If the protocol type is the TCP protocol type, identifying and processing the network data packet, obtaining a first service port and calculating a first confidence level of the first service port;
[0136] If the protocol type is the UDP protocol type, the network data packet is identified and processed to obtain a second service port and calculate a second confidence level of the second service port.
[0137] Preferably, in any of the above embodiments, the port identification module 300 is specifically used for:
[0138] When the service port is the first service port, determine whether the first service port is consistent with the third service port, if they are consistent, output the determination result to complete the identification, if they are inconsistent, select the service port with higher confidence among the first confidence and the third confidence as the output result to complete the identification; or
[0139] When the service port is the second service port, determine whether the second service port is consistent with the third service port. If they are consistent, output the judgment result to complete the identification. If they are inconsistent, select the service port with higher confidence among the second confidence and the third confidence as the output result to complete the identification.
[0140] Preferably, in any of the above embodiments, the third service port identified by the service port one-to-many learning submodule is specifically:
[0141] Based on the statistical dictionary, a first corresponding number is counted, the first corresponding number is the number of ports that have been connected to the source port in the network data packet, and a second corresponding number is counted, the second corresponding number is the number of ports that have been connected to the destination port in the network data packet, and it is determined whether the first corresponding number and the second corresponding number are greater than a threshold value. If only the first corresponding number is greater than the threshold value, the source port is output as a third service port; if only the second corresponding number is greater than the threshold value, the destination port is output as a third service port; if both the first corresponding number and the second corresponding number are not greater than the threshold value, the third service port is not output; if both the first corresponding number and the second corresponding number are greater than the threshold value, the first corresponding number and the second corresponding number are compared. If the first corresponding number is larger, the source port is output as the third service port, if the second corresponding number is larger, the destination port is output as the third service port, and if the first corresponding number and the second corresponding number are the same, the destination port is output as the third service port, wherein the statistical dictionary is composed of key-value pairs, wherein the key is the source port and the destination port in each network data packet, and the value is the number of ports that the source port or the destination port has been connected.
[0142] Preferably, in any of the above embodiments, if the protocol type is a TCP protocol type, the network data packet is identified and processed to obtain the first service port specifically as:
[0143] Inputting the identified TCP network data packet into the TCP communication service port identification submodule, the TCP communication service port identification submodule determines the type of the network data packet;
[0144] If the type is determined to be a SYN packet, the destination port in the network packet is the first service port;
[0145] If the type is determined to be a SYNACK data packet, the source port in the network data is the first service port;
[0146] If the type is judged to be neither a SYN packet nor a SYNACK packet, and the source port and the destination port in the network packet are not equal, then the source port and the destination port in the network packet are searched in the TCP service port table. If only the source port is searched, the source port is the first service port. If only the destination port is searched, the destination port is the first service port. If both the source port and the destination port are searched, the confidences of the source port and the destination port are compared. The port with a higher confidence is the first service port. If the confidences are consistent, the port with a smaller port number between the source port and the destination port is the first service port.
[0147] If the type is judged to be neither a SYN packet nor a SYNACK packet, and the source port and the destination port in the network packet are equal, then the source IP address and the destination IP address in the network packet are compared. If the source IP address is larger, the source port is the first service port; if the destination IP address is larger, the destination port is the first service port.
[0148] Preferably, in any of the above embodiments, if the protocol type is a UDP protocol type, the network data packet is identified and processed to obtain the second service port specifically as:
[0149] Input the identified UDP network data packet into the UDP communication service port identification submodule, and the UDP communication service port identification submodule determines whether the lowest bit of the first byte of the destination MAC address is 1;
[0150] If it is 1, the communication is multicast communication, and the destination port in the network data packet is the second service port;
[0151] If it is not 1, and the source port and the destination port in the network data packet are not equal, then the source port and the destination port in the network data packet are searched in the UDP service port table. If only the source port is searched, the source port is the second service port. If only the destination port is searched, the destination port is the second service port. If both the source port and the destination port are searched, the confidences of the source port and the destination port are compared. The port with a higher confidence is the second service port. If the confidences are consistent, the port with a smaller port number between the source port and the destination port is the second service port.
[0152] If it is not 1, and the source port and destination port in the network data packet are equal, then compare the source IP address and destination IP address in the network data packet. If the source IP address is larger, the source port is the first service port; if the destination IP address is larger, the destination port is the first service port.
[0153] Preferably, in any of the above embodiments, the confidence of the service port is calculated as follows:
[0154] The confidence calculation submodule is called to calculate the confidence of the service port.
[0155] Preferably, in any of the above embodiments, the calling of the confidence calculation submodule to calculate the confidence of the service port is specifically:
[0156] Calculate the dimension confidence of different dimensions of the service port, and add the dimension confidence of each dimension according to the weight corresponding to each dimension to obtain the total confidence. When the total confidence reaches the second threshold, the confidence calculation for the port is no longer performed;
[0157] Among them, the calculation formula of dimension confidence c is as follows:
[0158] c=100×(1-0.4 x )×w
[0159] Wherein, x is the number of times the recognition condition is met and when x reaches the first threshold, it will no longer increase, and w is the weight.
[0160] Preferably, in any of the above embodiments, it further comprises:
[0161] The error self-check module is used to search in the storage database whether there is a historical service port that is opposite to the client IP address of the identified service port and the server IP address of the identified service port after completing the identification. If not, the identified service port is stored in the storage database. If so, it is determined whether the confidence of the identified service port is less than the confidence of the historical service port. If so, it is determined that the identified service port is wrong and is not stored. If so, it is determined that the historical service port is wrong, and the relevant data of the historical service port is deleted in the storage database, and the identified service port is stored in the storage database.
[0162] A storage medium stores instructions, and when a computer reads the instructions, the computer executes a service port identification method as described in any one of the above items.
[0163] In some possible implementations, by classifying network data packets and then identifying service ports, the identification efficiency can be faster and more accurate. In particular, the one-to-many learning submodule of the service port solves the problem that the service ports of UDP communication and TCP long connection communication are difficult to identify. In addition, by calculating the confidence level, the problem of inaccurate identification when the source port and the destination port meet the same conditions is solved, which greatly improves the accuracy of service port identification.
[0164] An electronic device comprises a memory, a processor and a program stored in the memory and running on the processor, wherein when the processor executes the program, a service port identification method as described in any one of the above items is implemented.
[0165] In some possible implementations, by classifying network data packets and then identifying service ports, the identification efficiency can be faster and more accurate. In particular, the one-to-many learning submodule of the service port solves the problem that the service ports of UDP communication and TCP long connection communication are difficult to identify. In addition, by calculating the confidence level, the problem of inaccurate identification when the source port and the destination port meet the same conditions is solved, which greatly improves the accuracy of service port identification.
[0166] The reader should understand that in the description of this specification, the description with reference to the terms "one embodiment", "some embodiments", "examples", "specific examples", or "some examples" etc. means that the specific features, structures, materials or characteristics described in conjunction with the embodiment or example are included in at least one embodiment or example of the present invention. In this specification, the schematic representations of the above terms do not necessarily refer to the same embodiment or example. Moreover, the specific features, structures, materials or characteristics described may be combined in any one or more embodiments or examples in a suitable manner. In addition, those skilled in the art may combine and combine different embodiments or examples described in this specification and the features of different embodiments or examples without contradiction.
[0167] In the several embodiments provided in this application, it should be understood that the disclosed devices and methods can be implemented in other ways. For example, the method embodiments described above are only illustrative, for example, the division of steps is only a logical function division, and there may be other division methods in actual implementation, such as multiple steps can be combined or integrated into another step, or some features can be ignored or not executed.
[0168] If the above method is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present invention is essentially or the part that contributes to the prior art, or all or part of the technical solution can be embodied in the form of a software product, and the computer software product is stored in a storage medium, including a number of 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 methods of 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 and other media that can store program codes.
[0169] The above are only specific embodiments of the present invention, but the protection scope of the present invention is not limited thereto. Any technician familiar with the technical field can easily think of various equivalent modifications or replacements within the technical scope disclosed by the present invention, and these modifications or replacements should be included in the protection scope of the present invention. Therefore, the protection scope of the present invention shall be based on the protection scope of the claims.
Claims
1. A service port identification method, characterized in that: include: Step 1, classifying the protocols obtained from the network data packets, and then identifying the network data packets corresponding to the classified protocol types, obtaining the corresponding service ports and calculating the confidence of the service ports; Step 2, inputting the network data packet into the service port one-to-many learning submodule, identifying a third service port through the service port one-to-many learning submodule, and calculating a third confidence of the third service port; Step 3, judging whether the service port is consistent with the third service port, if they are consistent, outputting the judgment result to complete the identification, if they are inconsistent, selecting the service port with higher confidence among the confidence and the third confidence as the output result to complete the identification; The third service port identified by the service port one-to-many learning submodule is specifically: Based on the statistical dictionary, counting a first corresponding number, the first corresponding number is the number of ports that have been connected to the source port in the network data packet, and counting a second corresponding number, the second corresponding number is the number of ports that have been connected to the destination port in the network data packet, determining whether the first corresponding number and the second corresponding number are greater than a threshold value, and if only the first corresponding number is greater than the threshold value, outputting the source port as a third service port; If only the second corresponding quantity is greater than the threshold, the destination port is output as the third service port; If both the first corresponding number and the second corresponding number are not greater than the threshold, the third service port is not output; if both the first corresponding number and the second corresponding number are greater than the threshold, the first corresponding number and the second corresponding number are compared, if the first corresponding number is larger, the source port is output as the third service port, if the second corresponding number is larger, the destination port is output as the third service port, if the first corresponding number and the second corresponding number are the same, the destination port is output as the third service port, wherein the statistical dictionary consists of key-value pairs, wherein the key is the source port and destination port in each network data packet, and the value is the number of ports that the source port or the destination port has been connected to.
2. A service port identification method according to claim 1, characterized in that: The step 1 specifically includes: If the protocol type is the TCP protocol type, identifying and processing the network data packet, obtaining a first service port and calculating a first confidence level of the first service port; If the protocol type is the UDP protocol type, the network data packet is identified and processed to obtain a second service port and calculate a second confidence level of the second service port.
3. A service port identification method according to claim 2, characterized in that: The step 3 specifically includes: When the service port is the first service port, determine whether the first service port is consistent with the third service port; if they are consistent, output the determination result to complete the identification; if they are inconsistent, select the service port with higher confidence among the first confidence and the third confidence as the output result to complete the identification; or When the service port is the second service port, determine whether the second service port is consistent with the third service port. If they are consistent, output the judgment result to complete the identification. If they are inconsistent, select the service port with higher confidence among the second confidence and the third confidence as the output result to complete the identification.
4. A service port identification method according to claim 2, characterized in that: If the protocol type is the TCP protocol type, the network data packet is identified and processed, and the first service port is obtained as follows: Inputting the identified TCP network data packet into the TCP communication service port identification submodule, the TCP communication service port identification submodule determines the type of the network data packet; If the type is determined to be a SYN packet, the destination port in the network packet is the first service port; If the type is determined to be a SYNACK data packet, the source port in the network data is the first service port; If the type is judged to be neither a SYN packet nor a SYNACK packet, and the source port and the destination port in the network packet are not equal, then the source port and the destination port in the network packet are searched in the TCP service port table. If only the source port is searched, the source port is the first service port. If only the destination port is searched, the destination port is the first service port. If both the source port and the destination port are searched, the confidences of the source port and the destination port are compared. The port with a higher confidence is the first service port. If the confidences are consistent, the port with a smaller port number between the source port and the destination port is the first service port. If the type is judged to be neither a SYN packet nor a SYNACK packet, and the source port and the destination port in the network packet are equal, then the source IP address and the destination IP address in the network packet are compared. If the source IP address is larger, the source port is the first service port; if the destination IP address is larger, the destination port is the first service port.
5. A service port identification method according to claim 2, characterized in that: If the protocol type is the UDP protocol type, the network data packet is identified and processed to obtain the second service port: Input the identified UDP network data packet into the UDP communication service port identification submodule, and the UDP communication service port identification submodule determines whether the lowest bit of the first byte of the destination MAC address is 1; If it is 1, the communication is multicast communication, and the destination port in the network data packet is the second service port; If it is not 1, and the source port and the destination port in the network data packet are not equal, then the source port and the destination port in the network data packet are searched in the UDP service port table. If only the source port is searched, the source port is the second service port. If only the destination port is searched, the destination port is the second service port. If both the source port and the destination port are searched, the confidences of the source port and the destination port are compared. The port with a higher confidence is the second service port. If the confidences are consistent, the port with a smaller port number between the source port and the destination port is the second service port. If it is not 1, and the source port and destination port in the network data packet are equal, then compare the source IP address and destination IP address in the network data packet. If the source IP address is larger, the source port is the second service port; if the destination IP address is larger, the destination port is the second service port.
6. A service port identification method according to claim 1, characterized in that: The confidence of the service port is calculated as follows: The confidence calculation submodule is called to calculate the confidence of the service port.
7. A service port identification method according to claim 6, characterized in that: The calling confidence calculation submodule to calculate the confidence of the service port is specifically: Calculate the dimension confidence of different dimensions of the service port, and add the dimension confidence of each dimension according to the weight corresponding to each dimension to obtain the total confidence. When the total confidence reaches the second threshold, the confidence calculation for the port is no longer performed; Among them, the calculation formula of dimension confidence c is as follows: c=100×(1-0.4 x )×w Wherein, x is the number of times the recognition condition is met and when x reaches the first threshold, it will no longer increase, and w is the weight.
8. A service port identification method according to claim 1, characterized in that: Also includes: After the identification is completed, the storage database is searched to see whether there is a historical service port that is opposite to the client IP address of the identified service port and the server IP address of the identified service port. If not, the identified service port is stored in the storage database. If so, it is determined whether the confidence of the identified service port is less than the confidence of the historical service port. If so, the identified service port is determined to be wrong, and is not stored and corrected. If so, the historical service port is determined to be wrong, and the relevant data of the historical service port is deleted from the storage database, and the identified service port is stored in the storage database.
9. A service port identification system, characterized in that: include: A port acquisition module, used to classify the protocols obtained from the network data packets, and then identify and process the network data packets corresponding to the classified protocol types, obtain the corresponding service ports and calculate the confidence of the service ports; A port learning module, used for inputting the network data packet into a service port one-to-many learning submodule, identifying a third service port through the service port one-to-many learning submodule, and calculating a third confidence of the third service port; a port identification module, configured to determine whether the service port is consistent with the third service port, and if so, output a determination result to complete identification; if not, select a service port with a higher confidence level among the confidence level and the third confidence level as an output result to complete identification; The third service port identified by the service port one-to-many learning submodule is specifically: Based on the statistical dictionary, counting a first corresponding number, the first corresponding number is the number of ports that have been connected to the source port in the network data packet, and counting a second corresponding number, the second corresponding number is the number of ports that have been connected to the destination port in the network data packet, determining whether the first corresponding number and the second corresponding number are greater than a threshold value, and if only the first corresponding number is greater than the threshold value, outputting the source port as a third service port; If only the second corresponding quantity is greater than the threshold, the destination port is output as the third service port; If both the first corresponding number and the second corresponding number are not greater than the threshold, the third service port is not output; if both the first corresponding number and the second corresponding number are greater than the threshold, the first corresponding number and the second corresponding number are compared, if the first corresponding number is larger, the source port is output as the third service port, if the second corresponding number is larger, the destination port is output as the third service port, if the first corresponding number and the second corresponding number are the same, the destination port is output as the third service port, wherein the statistical dictionary consists of key-value pairs, wherein the key is the source port and destination port in each network data packet, and the value is the number of ports that the source port or the destination port has been connected to.
