Firewall is an essential protective component in an enterprise or academic network environment. It filters packets, blocks malicious connections, and prevents internal hosts from attacks. However, as the number and complexity of firewall rules grow,
there are conflicting behaviours between rules. Any error can cause unwanted traffic pass or blocking desired traffic. In the paper Abedin, M., et al., they have proposed four relations between the rules: disjoint, exactly matching, inclusively matching, and correlated. Based on these relations, there are three possible anomalies: shadowing anomaly, correlation anomaly, and redundancy anomaly.
I've implemented the anomaly resolution algorithm in Abedin, M., et al. for resolving for Ryu restful firewall. The code is held at this repository.
Program Structure
There are four classes:
RuleParser: an abstract class that holds a list of rules and defines an abstract function, parse_file
SimpleRuleParser
Rule
AnomalyResolver
SimpleRuleParser
SimpleRuleParser is an implementation of RuleParser that parses a firewall rules file in the following format:
Each line is a firewall rule. You can implement RuleParser to support different format of firewall rules file.
Rule
Rule contains the following fields which are defined in Ryu restful firewall and OpenFlow Specification. In order to stay flexible, most of these fields are stored in string.
When initializing a Rule, _sanity_check is called to check whether the string in each field is valid.
disjoint, issubset, and contiguous check the relations between two rules. issubset is inclusively matching in the paper.
AnomalyResolver
detect_anomalies accepts a rules list and reports any detected anomaly.
resolve_anomalies follows the algorithm describe in the paper. First, create a new rules list, insert old rules into it one by one, and check for redundancy.
insert checks if a rule is disjoint with rules inside the new rules list. If not, resolve for these two rules.
resolve performs anomaly detection and resolution by removing, reordering, or calling split.
split extracts the parts of the rules which are disjoint to the two rules and creates a new rule with the common part.
merge_contiguous_rules first calls construct_rule_tree, and merge contiguous rules.
construct_rule_tree creates a firewall rule tree.
tree_insert inserts a rule into a node of the rule tree.
get_rule_tree_root
merge merges edges of a node representing a contunous range.
cut_edge removes an edge from the rule tree.
subtree_equal checks if the subtree of an edges is equal to that of the other edge.
Conclusion
Firewall rule anomalies can result in security breaches. However, manual detecting and resolving these anomalies is an error prone task. With this algorithm, we can write a program that resolve any anomaly present in the firewall rules by reoder and split operations.