A Suricata rule similarity calculation method based on edit distance

Through the suricata rule similarity calculation method based on edit distance, duplicate rules in the suricata rule file are automatically removed, which solves the problem of low efficiency of manual deduplication in the existing technology and improves the efficiency and security of network traffic detection.

CN118157970BActive Publication Date: 2024-09-27CHINESE PEOPLES LIBERATION ARMY UNIT 61660
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202410341694.9
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2024-03-25
Publication Date
2024-09-27
Estimated Expiration
2044-03-25

AI Technical Summary

Technical Problem

In the existing technology, there are a large number of duplicate rules in the suricata rule file, which results in low efficiency of manual deduplication, increases work complexity and risk of missed deletion, and affects the performance efficiency of network security detection.

Method used

The suricata rule similarity calculation method based on edit distance is used to automatically identify and remove similar rules by calculating the edit distance between rules, thereby reducing the impact of redundant rules on the performance of the suricata engine.

Benefits of technology

It improves the detection efficiency of the suricata engine, reduces the complexity of manual work, reduces the risk of missed deletions, and improves the performance and security of network traffic detection.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118157970B
    Figure CN118157970B
Patent Text Reader

Abstract

The present invention relates to a suricata rule similarity calculation method based on edit distance, belonging to the technical field of network security. In order to solve the problem of low efficiency of manual screening of duplicate rules, the present invention provides a more accurate, simpler, more convenient and more efficient similar rule deduplication automatic processing scheme through LD similarity detection, which improves the detection efficiency of the suricata engine, which will help reduce the adverse effects of redundant rules on the performance of the suricata engine, thereby improving the efficiency of network traffic detection.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The invention belongs to the technical field of network security, and in particular relates to a Suricata rule similarity calculation method based on edit distance. Background Art

[0002] With the continuous development of Internet technology, we are in an era of rapid evolution of network technology. This evolution is not only about the improvement of hardware and transmission speed, but also includes the transformation of a wider network ecosystem. Among them, the introduction of 5G technology is a milestone event, which brings us unprecedented high-speed, low-latency, and large-capacity communication capabilities, thus promoting the arrival of the era of the Internet of Everything.

[0003] With the popularization of the Internet of Everything, our daily life and working methods have undergone tremendous changes. Applications such as smart homes, smart cities, and industrial Internet of Things are becoming a reality, connecting various devices and systems to the Internet to achieve more efficient, convenient, and intelligent functions. However, this also brings a series of new challenges, especially network security issues.

[0004] The updating and iteration of network security technology has become an important issue in today's Internet field.

[0005] Suricata is a free, open source, mature, fast and robust network threat detection engine. It can be used for real-time intrusion detection (IDS), inline intrusion prevention (IPS), network security monitoring (NSM) and offline pcap processing. Suricata uses a powerful and extensive rule and signature language to inspect network traffic and provides powerful Lua scripting support to detect complex threats. In the prior art, there are a large number of duplicate rules in a suricata rule file, which mainly relies on manual deduplication, which has the disadvantages of missed detection, single but time-consuming work, and low efficiency.

[0006] Under current technology, Suricata is used by users to detect network traffic, mainly using rule-based detection solutions. The problem brought about is that there are a large number of similar rules between rules, which brings performance obstacles to the Suricata detection engine.

[0007] There are a large number of duplicate and similar rules in a rule file, which requires manual screening and removal of duplicate and similar rules. This greatly increases the complexity of manual work and is inefficient. It is not feasible for long-term persistent operations and is prone to problems such as missed deletions.

[0008] Rule management, performance efficiency, and network traffic volume are key issues in the field of network security:

[0009] 1. Challenges of rule management:

[0010] Rule management is the foundation of network security strategy, but it often becomes inconvenient in complex network environments. Traditional firewalls and intrusion detection systems often rely on manual configuration of rules, which can become very tedious and error-prone.

[0011] Technology Developments: Automated rule management tools and policy-based security management systems continue to evolve to help network administrators manage rules more effectively and reduce the risk of human error.

[0012] 2. Performance efficiency issues:

[0013] Network security solutions must maintain good performance while ensuring security. Poor performance may cause network delays, affect user experience, and even provide opportunities for attackers.

[0014] The impact of a large number of repeated rules is that the detection efficiency is low. Summary of the invention

[0015] 1. Technical issues to be resolved

[0016] The technical problem to be solved by the present invention is to design a Suricata rule similarity calculation method based on edit distance to solve the problem of low efficiency in manual screening of repeated rules.

[0017] (II) Technical solution

[0018] In order to solve the above technical problems, the present invention provides a Suricata rule similarity calculation method based on edit distance, comprising the following steps:

[0019] Step 1. Add a new rule in the web rule management and editing tool. After the rule passes the Suricata rule check, proceed to the next step;

[0020] Among them, the newly added rules are verified by Suricata rules based on the following legal rules:

[0021] alert http $HOME_NET any ->$EXTERNAL_NET any (msg:"HTTP GET RequestContaining Rule in URI"; flow:established,to_server; http.method; content:"GET"; http.uri; content:"rule"; fast_pattern; classtype:bad-unknown; sid:123;rev:1;)

[0022] The meaning of this rule is: get the http get request from the client to the server, and check whether there is the word "rule" in the requested URL; the rule uses the fast matching mode fast_pattern, the rule classification is unknown bad-unkown, the rule ID is 123, and when a data packet matching this rule is received, the alarm corresponding to this rule is triggered to generate rev:1.

[0023] Step 2. First, generalize the newly added rule and remove the data fields that do not need to participate in the edit distance comparison in the newly added rule to obtain a new rule;

[0024] In step 2, remove the rule ID and number of received packets from the newly added rule.

[0025] Step 3. Obtain all existing original rules from the rule file and generalize each rule;

[0026] Step 4. Perform LD calculations on the new rules and the generalized original rules one by one according to the edit distance LD calculation method, and calculate the similarity based on LD. When the similarity is greater than the set similarity threshold, the current new rule and the original rule are considered to be similar rules, and the similar rules are recorded in an array. After the LD calculations are completed for all the generalized new rules and the generalized original rules, the similar rules recorded in the array are returned to the web page.

[0027] Step 5. Output the array to the user, allowing the user to choose whether to delete or keep similar rules.

[0028] Preferably, in step S4, LD is calculated using the following method:

[0029] The edit distance between two strings a and b is expressed as lev a,b (|a|,|b|), where |a| and |b| correspond to the lengths of a and b respectively. Then, the edit distance between two strings a and b is described in the following mathematical language:

[0030]

[0031] In the above formula, define lev a,b (i,j) is the distance between the first i characters in a and the first j characters in b. Here, i and j are regarded as the length of a and b. The first character index of the string starts from 1, so the final edit distance is the distance when i=|a|,j=|b|: lev a,b (|a|,|b|);

[0032] When min(i,j)=0, it corresponds to the first i characters in string a and the first j characters in string b. At this time, one of i and j has a value of 0, indicating that one of strings a and b is an empty string. Then, to convert from a to b, only max(i,j) single-character edit operations are required, so the edit distance between them is max(i,j), which is the maximum of i and j.

[0033] When min(i,j)≠0, lev a,b (i,j) is the minimum value of the following three cases:

[0034] 1).lev a,b (i-1,j)+1, means deleting the i-th character a in string a i ,

[0035] 2).lev a,b (i,j-1)+1, means insert the jth character b of string b j

[0036] 3).lev a,b (i-1,j-1)+1 (ai≠bj) , which means replacing b j

[0037] Among them, 1 (ai≠bj) is an indicator function, indicating that when a i =b j When a i ≠b j , its value is 1.

[0038] Preferably, in step S4, the following matrix method is used to calculate LD:

[0039] Initialize the matrix d to be a matrix with m+1 rows and n+1 columns, and set all elements to 0. m and n are the lengths of strings s1 and s2 respectively.

[0040] Set the first column to 0...m;

[0041] Set the first row to 0...n;

[0042] Iterate over all characters in strings s1 and s2

[0043] If the current characters are the same, that is, s1[i-1] == s2[j-1], then d[i][j]= d[i-1][j-1], that is, the current distance remains unchanged. If the current characters are different, the current distance is set to the minimum value of the left, top, and upper-left elements plus 1: d[i][j]= min(d[i-1][j]+1, d[i][j-1]+1, d[i-1][j-1]+1);

[0044] d[m][n] is the edit distance between two strings.

[0045] Preferably, in step 4, the formula for calculating similarity is: similarity =1-distance / max(len(s1), len(s2)), where distance is the edit distance between two strings s1 and s2, and len(s1), len(s2) represent the lengths of the strings s1 and s2.

[0046] Preferably, the similarity threshold is adjusted according to actual conditions.

[0047] The invention also provides a system for implementing the method.

[0048] The invention also provides a network flow detection method implemented based on the method.

[0049] The invention also provides a network flow detection system implemented based on the method.

[0050] The present invention also provides an application of the Suricata similar rule deduplication method in the field of network security technology.

[0051] The present invention also provides an application of the network traffic detection method in the field of network security technology.

[0052] (III) Beneficial effects

[0053] The present invention provides a Suricata rule similarity calculation method based on edit distance, which is a Suricata similar rule deduplication method based on edit distance. A more accurate, simpler, more convenient and more efficient similar rule deduplication automatic processing solution is provided through LD similarity detection, which improves the detection efficiency of the Suricata engine, and will help reduce the adverse effects of redundant rules on the performance of the Suricata engine, thereby improving the efficiency of network traffic detection. BRIEF DESCRIPTION OF THE DRAWINGS

[0054] Figure 1 A schematic diagram of the overall architecture for realizing the concept of the present invention;

[0055] Figure 2 is a flow chart of the method of the present invention;

[0056] Figure 3 This is a flow chart of the present invention for calculating LD using a matrix method. DETAILED DESCRIPTION

[0057] In order to make the purpose, content and advantages of the present invention more clear, the specific implementation methods of the present invention are further described in detail below in conjunction with the drawings and examples.

[0058] The present invention focuses on actual network security needs and provides a suricata rule similarity calculation method based on edit distance, aiming to optimize the management of suricata rules. Among them, the focus is mainly on processing rules with high similarity, which will help reduce the adverse effects of redundant rules on the performance of the suricata engine, thereby improving the efficiency of network traffic detection. In general, the present invention is expected to improve the performance of the suricata engine and reduce the security risks of network traffic through more intelligent and efficient rule management. The present invention will help meet the growing network security needs and improve the availability and security of the network.

[0059] Levenshtein distance (LD) similarity detection refers to judging the similarity between two strings or texts by calculating the edit distance between them. The edit distance refers to the minimum number of edit operations required to transform one string into another. The allowed edit operations include replacing one character with another, inserting a character, and deleting a character. The smaller the edit distance, the more similar the two strings or texts are.

[0060] First, the calculation method of LD is given as follows:

[0061] The edit distance between two strings a and b is expressed as Levenshtein Distance a,b (|a|,|b|), where |a| and |b| correspond to the lengths of a and b respectively. So, here the Levenshtein Distance of the two strings a and b, that is, lev a,b (|a|,|b|) can be described in the following mathematical language:

[0062]

[0063] In the above formula, define lev a,b(i,j) is the distance between the first i characters in a and the first j characters in b. For ease of understanding, i and j here can be regarded as the length of a and b. The first character index of the string here starts at 1 (actually because the string needs to be padded with 0 when operating on the table), so the final edit distance is the distance when i=|a|,j=|b|:lev a,b (|a|,|b|)

[0064] When min(i,j)=0, it corresponds to the first i characters in string a and the first j characters in string b. At this time, one of i and j has a value of 0, indicating that one of strings a and b is an empty string. Then, converting from a to b only requires max(i,j) single-character editing operations, so the editing distance between them is max(i,j), which is the maximum of i and j.

[0065] When min(i,j)≠0, lev a,b (i,j) is the minimum value of the following three cases:

[0066] 1.lev a,b (i-1,j)+1, means deleting the i-th character a in string a i ,

[0067] 2.lev a,b (i,j-1)+1, means insert the jth character b of string b j

[0068] 3.lev a,b (i-1,j-1)+1 (ai≠bj) , which means replacing b j

[0069] Among them, 1 (ai≠bj) is an indicator function, indicating that when a i =b j When a i ≠b j , its value is 1.

[0070] refer to Figure 1 , Figure 2 The Suricata similar rule deduplication method based on edit distance of the present invention implemented based on the above formula includes the following steps:

[0071] Step 1. The user adds a new rule in the web rule management and editing tool. After the rule passes the Suricata rule verification, the next step is to perform the similarity function verification.

[0072] Among them, the newly added rules are verified by Suricata rules based on the following legal rules:

[0073] alert http $HOME_NET any ->$EXTERNAL_NET any (msg:"HTTP GET RequestContaining Rule in URI"; flow:established,to_server; http.method; content:"GET"; http.uri; content:"rule"; fast_pattern; classtype:bad-unknown; sid:123;rev:1;)

[0074] The meaning of this rule is: get the http get request from the client to the server, and check whether there is the word "rule" in the request URL; the rule adopts the fast matching mode (fast_pattern), the rule classification is "bad-unkown", the rule ID is 123, and when a data packet matching this rule is received, the alarm corresponding to this rule is triggered (rev: 1).

[0075] Step 2. First, generalize the newly added rule and remove the data fields (sid, rev, metadata) that do not need to participate in the edit distance comparison in the newly added rule. A new rule is obtained as follows:

[0076] alert http $HOME_NET any ->$EXTERNAL_NET any (msg:"HTTP GET RequestContaining Rule in URI"; flow:established,to_server; http.method; content:"GET"; http.uri; content:"rule"; fast_pattern; classtype:bad-unknown;)

[0077] This rule has the same meaning as the above rule. However, when calculating the edit distance, some useless elements in the rule need to be deleted to avoid errors caused by affecting the similarity calculation. In this rule, the rule ID and the number of received packets are deleted.

[0078] Step 3. Get all existing original rules from the rule file and generalize each rule.

[0079] Step 4. The new rules and the generalized original rules are cycled through LD calculation one by one according to the LD calculation method above, and the similarity is calculated based on LD. When the similarity is greater than 0.9 (or the set threshold), the current new rules and the original rules are considered to be similar rules. The similar rules are recorded in an array, and the generalized new rules and the generalized original rules are continued to perform LD calculations in turn until the LD calculations for all rules are completed, and the similar rules recorded in the array are returned to the web page.

[0080] Step 5. Output the array to the user, allowing the user to choose whether to delete or keep similar rules.

[0081] In order to make the calculation easier, in step S4, the following matrix method can also be used to calculate LD (refer to Figure 3 ):

[0082] Initialize the matrix d to be a matrix with m+1 rows and n+1 columns, with all elements set to 0 (m and n are the lengths of strings s1 and s2 respectively)

[0083] Set the first column to 0...m (i from 1 to m)

[0084] Set the first row to 0...n (j from 1 to n)

[0085] Iterate over all characters in strings s1 and s2

[0086] If the current characters are the same (s1[i-1] == s2[j-1]), then d[i][j] = d[i-1][j-1], that is, the current distance remains unchanged

[0087] If they are different, the current distance is the minimum value of the left, top, and top-left elements plus 1:

[0088] d[i][j]= min(d[i-1][j]+1, d[i][j-1]+1, d[i-1][j-1]+1)

[0089] Finally, d[m][n] is the edit distance between the two strings.

[0090] For example, for the strings "kitten" and "sitting":

[0091] m = 6, n = 7

[0092] Initialize d to: [

[0094] [0, 1, 2, 3, 4, 5, 6],

[0095] [1, 0, 0, 0, 0, 0, 0],

[0096] [2, 0, 0, 0, 0, 0, 0],

[0097] [3, 0, 0, 0, 0, 0, 0],

[0098] [4, 0, 0, 0, 0, 0, 0],

[0099] [5, 0, 0, 0, 0, 0, 0],

[0100] [6, 0, 0, 0, 0, 0, 0] ]

[0102] Set the first column to [0, 1, 2, 3, 4, 5, 6]

[0103] Set the first line to [0, 1, 2, 3, 4, 5, 6, 7]

[0104] Compare each character:

[0105] k vs s: not the same, d[1][1] = min(1, 1, 0) + 1 = 1

[0106] i vs i: same, d[2][2]= d[1][1]= 1

[0107] t vs t: same, d[3][3]= d[2][2]= 1 ...

[0109] The final distance is d[6][7] = 3

[0110] So the edit distance between "kitten" and "sitting" is 3.

[0111] In step 4, the formula for calculating similarity is: similarity =1-distance / max(len(s1), len(s2)), where len(s1), len(s2) represent the length of strings s1 and s2. Here, the edit distance divided by the maximum length of the two strings is used as the difference measure, and 1 minus the difference is the similarity. Substituting the calculation result of the above example into the formula, we can get: similarity =1–3 / max(6, 7), and the final similarity result is approximately equal to 0.57. The similarity threshold is adjusted according to the actual situation.

[0112] The above is only a preferred embodiment of the present invention. It should be pointed out that for ordinary technicians in this technical field, several improvements and modifications can be made without departing from the technical principles of the present invention. These improvements and modifications should also be regarded as the scope of protection of the present invention.

Claims

1. A method for calculating the similarity of Suricata rules based on edit distance, It is characterized in that The following steps are involved: Step 1. Add a new rule in the web rule management and editing tool. After the rule passes the Suricata rule check, proceed to the next step; Among them, the newly added rules are verified by Suricata rules based on the following legal rules: alert http $HOME_NET any -> $EXTERNAL_NET any, msg:"HTTP GET RequestContaining Rule in URI"; flow:established,to_server; http.method; content:"GET"; http.uri; content:"rule"; fast_pattern; classtype:bad-unknown; sid:123;rev:1; The meaning of this rule is: get the http get request from the client to the server, and check whether there is the word "rule" in the request URL; the rule adopts the fast matching mode fast_pattern, the rule classification is unknown bad-unkown, the rule ID is 123, and when a data packet matching this rule is received, the alarm corresponding to this rule is triggered to generate rev:1; Step 2. First, generalize the newly added rule and remove the data fields that do not need to participate in the edit distance comparison in the newly added rule to obtain a new rule; In step 2, remove the rule ID and number of received packets in the newly added rule; Step 3. Obtain all existing original rules from the rule file and generalize each rule; Step 4. Perform LD calculations on the new rules and the generalized original rules one by one according to the edit distance LD calculation method, and calculate the similarity based on LD. When the similarity is greater than the set similarity threshold, the current new rule and the original rule are considered to be similar rules, and the similar rules are recorded in an array. After the LD calculations are completed for all the generalized new rules and the generalized original rules, the similar rules recorded in the array are returned to the web page. Step 5. Output the array to the user, allowing the user to choose whether to delete or keep similar rules.

2. The method according to claim 1, It is characterized in that In step S4, LD is calculated using the following method: The edit distance between two strings a and b is expressed as lev a,b (|a|,|b|), where |a| and |b| correspond to the lengths of a and b respectively. Then, the edit distance between two strings a and b is described by the following formula: ; In the formula, define lev a,b (i,j) is the distance between the first i characters in a and the first j characters in b. Here, i and j are regarded as the length of a and b. The first character index of the string starts from 1, so the final edit distance is the distance when i=|a|,j=|b|: lev a,b (|a|,|b|); When min(i,j)=0, it corresponds to the first i characters in string a and the first j characters in string b. At this time, one of i and j has a value of 0, indicating that one of strings a and b is an empty string. Then, only max(i,j) single-character edit operations are performed from a to b, so the edit distance between them is max(i,j), which is the maximum of i and j. When min(i,j)≠0, lev a,b (i,j) is the minimum value of the following three cases: 1).lev a,b (i-1,j)+1, means deleting the i-th character a in string a i , 2).lev a,b (i,j-1)+1, means insert the jth character b of string b j 3).lev a,b (i-1,j-1)+1 (ai≠bj) , which means replacing b j Among them, 1 (ai≠bj) is an indicator function, indicating that when a i =b j When a i ≠b j , its value is 1.

3. The method according to claim 1, It is characterized in that In step S4, the following matrix method is used to calculate LD: Initialize the matrix d to be a matrix with m+1 rows and n+1 columns, and set all elements to 0. m and n are the lengths of strings s1 and s2 respectively. Set the first column to 0...m; Set the first row to 0...n; Iterate over all characters in strings s1 and s2 If the current characters are the same, that is, s1[i-1] == s2[j-1], then d[i][j] = d[i-1][j-1], that is, the current distance remains unchanged. If the current characters are different, the current distance is set to the minimum value of the left, top, and upper-left elements plus 1: d[i][j] = min(d[i-1][j]+1, d[i][j-1]+1, d[i-1][j-1]+1); d[m][n] is the edit distance between two strings.

4. The method according to claim 2 or 3, It is characterized in that In step 4, the formula for calculating similarity is: similarity = 1-distance / max(len(s1), len(s2)), where distance is the edit distance between the two strings s1 and s2, and len(s1), len(s2) represents the length of the strings s1 and s2.

5. The method according to claim 1, It is characterized in that The similarity threshold is adjusted according to the actual situation.

6. A system for implementing the method according to any one of claims 1 to 5.

7. A network traffic detection method implemented based on the method according to any one of claims 1 to 5.

8. A network traffic detection system implemented based on the method according to any one of claims 1 to 5.

9. Application of the method according to any one of claims 1 to 5 in the field of network security technology.

10. An application of the method according to claim 7 in the field of network security technology.