Audit ordered ACL decisions
Trace ordered ACL matches, identify a shadowed deny rule and verify packet decisions after reordering.

Shield Shelly
The Security Threats guide directs learners from network defense to recurring security mistakes and review evidence.
Predict the reading, then compare it with the measurement.
Python 3 in your browser (JupyterLite)
Python · no installOpen the notebook in your browser and run each Python cell; no install or account is needed.
Three ways to run: use JupyterLite here with no install; run main.py locally from the downloadable lab folder; or open the same notebook in Google Colab.
Steps
Step 1
- Do
- Run the first notebook cell in the editor and inspect the synthetic ordered ACL and packet fixture.
- You will see
Run the cell. You should see:
- Synthetic ordered ACL; packets are fixtures, not Packet Tracer captures
- A1: permit 10.1.0.0/24 -> 10.2.0.10 tcp/1883
- A2: deny 10.1.0.66/32 -> 10.2.0.10 tcp/1883
- A3: permit 10.1.0.0/24 -> 10.2.0.10 icmp/-
- Unmatched packets: implicit deny
- STEP 1 ACL and packets fixed
- Why it matters
- Rule order, protocol and source prefix are explicit inputs to every decision.
Code for step 1#!/usr/bin/env python3 """Synthetic ordered ACL audit; no Packet Tracer execution is implied.""" from ipaddress import ip_address, ip_network rules = [ ("A1", "permit", "10.1.0.0/24", "10.2.0.10", "tcp", 1883), ("A2", "deny", "10.1.0.66/32", "10.2.0.10", "tcp", 1883), ("A3", "permit", "10.1.0.0/24", "10.2.0.10", "icmp", None), ] packets = [ ("K1", "10.1.0.20", "10.2.0.10", "tcp", 1883), ("K2", "10.1.0.66", "10.2.0.10", "tcp", 1883), ("K3", "10.1.0.20", "10.2.0.10", "icmp", None), ("K4", "10.1.0.66", "10.2.0.10", "udp", 1883), ("K5", "10.3.0.8", "10.2.0.10", "tcp", 1883), ] print("Synthetic ordered ACL; packets are fixtures, not Packet Tracer captures") for rid, effect, src, dst, proto, port in rules: print(f"{rid}: {effect:6} {src:14} -> {dst} {proto}/{port or '-'}") print("Unmatched packets: implicit deny") print("STEP 1 ACL and packets fixed")
10.2.0.10 tcp/1883" loading="lazy">Step 1 · Python 3 in your browser (JupyterLite); numbered callout added to a real capture. Step 2
- Do
- Run the second cell in the editor and inspect first-match packet decisions in the output table.
- You will see
Run the cell. You should see:
- packet source protocol destination decision first-rule
- K1 10.1.0.20 tcp 10.2.0.10 permit A1
- K2 10.1.0.66 tcp 10.2.0.10 permit A1
- K3 10.1.0.20 icmp 10.2.0.10 permit A3
- K4 10.1.0.66 udp 10.2.0.10 deny implicit-deny
- K5 10.3.0.8 tcp 10.2.0.10 deny implicit-deny
- STEP 2 first-match decisions computed
- Why it matters
- First match determines the action; unmatched packets meet the implicit deny.
Code for step 2def matches(rule, packet): _, _, src_net, dst, proto, port = rule _, src, target, packet_proto, packet_port = packet return (ip_address(src) in ip_network(src_net) and target == dst and packet_proto == proto and packet_port == port) def decide(packet, ordered_rules): for rule in ordered_rules: if matches(rule, packet): return rule[1], rule[0] return "deny", "implicit-deny" print("packet source protocol destination decision first-rule") for packet in packets: action, rid = decide(packet, rules) print(f"{packet[0]:6} {packet[1]:12} {packet[3]:5} {packet[2]:15} {action:7} {rid}") print("STEP 2 first-match decisions computed")
Step 2 · Python 3 in your browser (JupyterLite); numbered callout added to a real capture. Step 3
- Do
- Run the third cell in the editor and inspect the shadowed-rule explanation for packet K2.
- You will see
Run the cell. You should see:
- K2 source=10.1.0.66 matches ordered rules: A1, A2
- First match=A1 -> permit
- A2 intended deny is shadowed by A1's broader permit
- A2 source is inside A1's /24 and matches same destination/protocol/port
- This is an ACL rule-order defect, not a claim about router state
- STEP 3 shadowed rule shown
- Why it matters
- The narrow deny cannot fire while a broader matching permit precedes it.
Code for step 3candidate = packets[1] matching = [r[0] for r in rules if matches(r, candidate)] print(f"K2 source={candidate[1]} matches ordered rules: {', '.join(matching)}") print(f"First match={matching[0]} -> {decide(candidate, rules)[0]}") print("A2 intended deny is shadowed by A1's broader permit") print("A2 source is inside A1's /24 and matches same destination/protocol/port") print("This is an ACL rule-order defect, not a claim about router state") print("STEP 3 shadowed rule shown")
permit" loading="lazy">Step 3 · Python 3 in your browser (JupyterLite); numbered callout added to a real capture. Step 4
- Do
- Run the fourth cell in the editor and inspect before-and-after decisions after moving A2 first.
- You will see
Run the cell. You should see:
- Fix order: A2 deny before A1 permit, then A3 ICMP permit
- packet before/rule after/rule
- K1 permit/A1 permit/A1
- K2 permit/A1 deny /A2
- K3 permit/A3 permit/A3
- K4 deny /implicit-deny deny /implicit-deny
- K5 deny /implicit-deny deny /implicit-deny
- STEP 4 reordered ACL replayed
- Why it matters
- The replay tests the intended deny and checks that legitimate paths stay permitted.
Code for step 4fixed_rules = [rules[1], rules[0], rules[2]] print("Fix order: A2 deny before A1 permit, then A3 ICMP permit") print("packet before/rule after/rule") for packet in packets: before = decide(packet, rules) after = decide(packet, fixed_rules) print(f"{packet[0]:6} {before[0]:6}/{before[1]:13} {after[0]:6}/{after[1]}") print("STEP 4 reordered ACL replayed")
Step 4 · Python 3 in your browser (JupyterLite); numbered callout added to a real capture. Step 5
- Do
- Run the final cell in the editor and inspect packet assertions and the Packet Tracer boundary note.
- You will see
Run the cell. You should see:
- K2 attacker TCP/1883: deny/A2
- K1 legitimate TCP/1883: permit/A1
- K3 ICMP: permit/A3
- K4 UDP and K5 outside subnet: deny/implicit-deny
- Five expected packet decisions: PASS
- This notebook does not establish Packet Tracer or hardware enforcement.
- STEP 5 ACL invariants validated
- Why it matters
- Assertions verify the model's expected decisions, while deployment needs a separate router test.
Code for step 5expected = {"K1":"permit", "K2":"deny", "K3":"permit", "K4":"deny", "K5":"deny"} for packet in packets: assert decide(packet, fixed_rules)[0] == expected[packet[0]] assert decide(packets[1], fixed_rules) == ("deny", "A2") print("K2 attacker TCP/1883: deny/A2") print("K1 legitimate TCP/1883: permit/A1") print("K3 ICMP: permit/A3") print("K4 UDP and K5 outside subnet: deny/implicit-deny") print("Five expected packet decisions: PASS") print("This notebook does not establish Packet Tracer or hardware enforcement.") print("STEP 5 ACL invariants validated")
Step 5 · Python 3 in your browser (JupyterLite); numbered callout added to a real capture.
Chapter checks
These questions refer to the chapter’s examples. Use the return links to review their answers.
What is the most useful way to frame a common IoT security mistake during review?
Return to the chapter’s knowledge checkA network review concludes an IoT device is well protected, but the shipped hardware still has an enabled serial console (UART) and an open chip debug interface (JTAG). Why does this weaken the conclusion?
Return to the chapter’s knowledge check
Caution
Before you start
Read this before you start.
The packets are synthetic; this notebook is not a Packet Tracer run and does not establish router enforcement.
Technical details
- Version tested
- Version tested: Python 3.12.7 / Pyodide 0.27.6 in JupyterLite 0.6.4; Chromium 148.0.7778.96; synthetic classroom fixtures. Date: 2026-10-08.
https://iotclass.org/labs/acl-decision-audit.html