My team reviewed firewall rules by hand for years. A small Python script now produces the first draft of the review in minutes.
Every quarter, someone on the team would open each firewall's rule base and go line by line looking for risky rules. It took days, it was boring, and results depended on who did it. So I automated the first pass.

What the script looks for
- Overly permissive rules:
anysource,anydestination, oranyservice, or very large subnets (say /8 to /16) as source or destination. - Shadowed rules: a rule that can never match because an earlier rule with the same or broader match already catches all its traffic.
- Unused rules: zero hit count over the review period.
- Hygiene: rules without comments, disabled rules nobody cleaned up, duplicate objects.
How it works
- Export the running config and hit counts from each firewall.
- Parse objects and object-groups into Python sets using the
ipaddressmodule. - Normalize every rule into (source set, destination set, service set, action).
- Compare each rule against every earlier rule: if A ⊇ B on all three dimensions, B is shadowed.
- Write the results to Excel with one sheet per firewall and a summary sheet.

A tiny piece of the logic
import ipaddress
def covers(a_nets, b_nets):
# True if every network in b is inside some network in a
return all(any(b.subnet_of(a) for a in a_nets) for b in b_nets)
def is_shadowed(earlier, rule):
return (covers(earlier.src, rule.src) and
covers(earlier.dst, rule.dst) and
rule.svc <= earlier.svc)
Results
The first run flagged dozens of shadowed rules and many unused ones on just two firewalls. Humans still decide what gets removed; the script just gives everyone the same starting point in minutes instead of days.
Tips if you build your own
- Start with one vendor and one firewall. Parsing is 80% of the work.
- Keep hit-count windows long enough to cover quarter-end and year-end jobs.
- Never auto-delete. Report, review, then change through normal change control.
Note: device names, IP addresses, AS numbers and user names in this post are pseudonyms or lab values. The problem and the fix are real.
0 Comments
Post a Comment