Skip to content

Commit 21f1b68

Browse files
committed
base: add basic packet-information to output
1 parent 7a58ffe commit 21f1b68

File tree

5 files changed

+38
-6
lines changed

5 files changed

+38
-6
lines changed

README.md

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,20 +31,22 @@ ftf-cli --firewall-system 'linux_netfilter' \
3131
--src-ip 172.17.11.5 \
3232
--dst-ip 2.2.2.2
3333

34+
> 🛈 SYSTEM: Processing packet: [172.17.11.5]:50000 =tcp=> [2.2.2.2]:443
3435
> 🛈 ROUTER: Packet inbound-interface: docker0
3536
> 🛈 ROUTER: Packet inbound-route: 172.17.0.0/16, scope link
36-
> 🛈 FIREWALL: Processing Chain: Table nat ip4 | Chain PREROUTING ip4 nat
37+
> 🛈 FIREWALL: Processing Chain: Table "nat" ip4 | Chain "PREROUTING" ip4 nat (1 rules)
3738
> 🛈 FIREWALL: > Chain PREROUTING | Rule 0 | Match => jump
38-
> 🛈 FIREWALL: > Chain PREROUTING | Sub-Chain: DOCKER
39+
> 🛈 FIREWALL: > Chain PREROUTING | Sub-Chain: DOCKER (2 rules)
3940
> 🛈 FIREWALL: > Chain DOCKER | Rule 0 | Match => return
4041
> 🛈 ROUTER: Packet outbound-interface: wan
41-
> 🛈 ROUTER: Packet outbound-route: 0.0.0.0/0, gw 10.255.255.254, metric 600, scope remote
42-
> 🛈 FIREWALL: Processing Chain: Table filter ip4 | Chain FORWARD ip4 filter
42+
> 🛈 ROUTER: Packet outbound-route: 0.0.0.0/0, gw 10.255.255.254, metric 600, scope global
43+
> 🛈 FIREWALL: Processing Chain: Table "filter" ip4 | Chain "FORWARD" ip4 filter (5 rules)
4344
> 🛈 FIREWALL: > Chain FORWARD | Rule 0 | Match => jump
44-
> 🛈 FIREWALL: > Chain FORWARD | Sub-Chain: DOCKER-USER
45+
> 🛈 FIREWALL: > Chain FORWARD | Sub-Chain: DOCKER-USER (1 rules)
4546
> 🛈 FIREWALL: > Chain DOCKER-USER | Rule 0 | Match => return
4647
> 🛈 FIREWALL: > Chain FORWARD | Rule 1 | Match => drop
47-
> ✖ FIREWALL: Packet blocked by rule: {'action': 'drop', 'seq': 1, 'raw': Rule: #101 "TEST DROP" | Matches: [proto_l3 == ip4 & ip_daddr == ['2.2.2.2/32']]}
48+
> ✖ FIREWALL: Packet blocked by rule: Seq 1, Action: drop, Rule: #101 "TEST IP4-DADDR DROP"
49+
> > Matches: {'proto_l3': {'==': 'ip4'}, 'ip_daddr': {'==': ['2.2.2.2/32']}}
4850
```
4951

5052
----

docs/source/plugins/firewall_opnsense.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ Example
6666
> ⚠ FIREWALL PLUGIN: Unsupported rule: Chain interfaces, Rule 80
6767
> ⚠ FIREWALL PLUGIN: Unable to parse rule-address: "GEOIP_NEARBY"
6868
> ⚠ FIREWALL PLUGIN: Unsupported rule: Chain interfaces, Rule 85 (SVC_1 Proxies)
69+
> 🛈 SYSTEM: Processing packet: [10.34.28.206]:50000 =tcp=> [1.1.1.1]:993
6970
> 🛈 ROUTER: Packet inbound-interface: lan (LAN)
7071
> 🛈 ROUTER: Packet inbound-route: 10.34.28.0/24, scope link
7172
> 🛈 FIREWALL: Processing Chain: Table "default" ip | Chain "dnat" ip nat (0 rules)
@@ -104,6 +105,7 @@ Example
104105
ftf-cli ... --src-ip 10.34.28.206 --dst-ip 1.10.16.4
105106
106107
...
108+
> 🛈 SYSTEM: Processing packet: [10.34.28.206]:50000 =tcp=> [1.10.16.4]:443
107109
> 🛈 ROUTER: Packet inbound-interface: lan (LAN)
108110
> 🛈 ROUTER: Packet inbound-route: 10.34.28.0/24, scope link
109111
> 🛈 FIREWALL: Processing Chain: Table "default" ip | Chain "dnat" ip nat (0 rules)
@@ -124,6 +126,7 @@ Use the :code:`verbosity` flag to get more information about the rules and match
124126
ftf-cli ... --src-ip 10.34.28.206 --dst-ip 1.10.16.4 --verbosity 2
125127
126128
...
129+
> 🛈 SYSTEM: Processing packet: [10.34.28.206]:50000 =tcp=> [1.10.16.4]:443
127130
> 🛈 ROUTER: Packet inbound-interface: lan (LAN)
128131
> 🛈 ROUTER: Packet inbound-route: 10.34.28.0/24, scope link
129132
> 🛈 FIREWALL: Processing Chain: Table "default" ip | Chain "dnat" ip nat (0 rules)

docs/source/usage/3_run.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ Pass Example
7878
--src-ip 172.17.11.5 \
7979
--dst-ip 1.1.1.1
8080
81+
> 🛈 SYSTEM: Processing packet: [172.17.11.5]:50000 =tcp=> [1.1.1.1]:443
8182
> 🛈 ROUTER: Packet inbound-interface: docker0
8283
> 🛈 ROUTER: Packet inbound-route: 172.17.0.0/16, scope link
8384
> 🛈 FIREWALL: Processing Chain: Table nat ip4 | Chain PREROUTING ip4 nat
@@ -121,6 +122,7 @@ Block Example
121122
122123
ftf-cli ... --src-ip 172.17.11.5 --dst-ip 2.2.2.2
123124
125+
> 🛈 SYSTEM: Processing packet: [172.17.11.5]:50000 =tcp=> [2.2.2.2]:443
124126
> 🛈 ROUTER: Packet inbound-interface: docker0
125127
> 🛈 ROUTER: Packet inbound-route: 172.17.0.0/16, scope link
126128
> 🛈 FIREWALL: Processing Chain: Table nat ip4 | Chain PREROUTING ip4 nat
@@ -148,6 +150,7 @@ You can get more detailed output by increasing the verbosity:
148150
149151
ftf-cli ... --src-ip 172.17.11.5 --dst-ip 2.2.2.2 --verbosity 2
150152
153+
> 🛈 SYSTEM: Processing packet: [172.17.11.5]:50000 =tcp=> [2.2.2.2]:443
151154
> 🛈 ROUTER: Packet inbound-interface: docker0
152155
> 🛈 ROUTER: Packet inbound-route: 172.17.0.0/16, scope link
153156
> 🛈 FIREWALL: Processing Chain: Table nat ip4 | Chain PREROUTING ip4 nat
@@ -195,6 +198,7 @@ Depending on the system-specific configuration traffic can be dropped by non-fir
195198
196199
ftf-cli ... --src-ip 172.17.11.5 --dst-ip 10.100.1.1
197200
201+
> 🛈 SYSTEM: Processing packet: [172.17.11.5]:50000 =tcp=> [10.100.1.1]:443
198202
> 🛈 ROUTER: Packet inbound-interface: docker0
199203
> 🛈 ROUTER: Packet inbound-route: 172.17.0.0/16, scope link
200204
> 🛈 FIREWALL: Processing Chain: Table nat ip4 | Chain PREROUTING ip4 nat

src/firewall_test/simulator/main.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ def __init__(self, packet: PACKET_KINDS, simulator):
2828
self.dnat = None
2929
self.snat = None
3030

31+
log_info(label='System', v1=f'Processing packet: {packet}')
32+
3133
### CATEGORIZE TRAFFIC FLOW ###
3234

3335
self.local_src, packet.ni_in = self._is_ip_local(packet.src)

src/firewall_test/simulator/packet.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,12 @@ def dump(self) -> dict:
1414
'ni_out': self.ni_out,
1515
}
1616

17+
def __repr__(self) -> str:
18+
if self.ni_in is not None and self.ni_out is not None:
19+
return f'{self.ni_in} => {self.ni_out}'
20+
21+
return ''
22+
1723

1824
class PacketIP(Packet):
1925
def __init__(self, src: str, dst: str):
@@ -56,6 +62,15 @@ def dnat_str(self) -> str:
5662
def snat_str(self) -> str:
5763
return f'{self.pre_nat_src} => {self.src}'
5864

65+
def _repr_ni(self) -> str:
66+
if self.ni_in is not None and self.ni_out is not None:
67+
return f'{self.ni_in} => {self.ni_out} => '
68+
69+
return ''
70+
71+
def __repr__(self) -> str:
72+
return f'{self.src} => {self._repr_ni()}{self.dst}'
73+
5974

6075
class PacketTCPUDP(PacketIP):
6176
def __init__(
@@ -101,6 +116,9 @@ def dump(self) -> dict:
101116
def dnat_str(self) -> str:
102117
return f'{self.pre_nat_dst}:{self.pre_nat_dst_port} => {self.dst}:{self.dport}'
103118

119+
def __repr__(self) -> str:
120+
return f'[{self.src}]:{self.sport} ={self.proto_l4.N}=> {self._repr_ni()}[{self.dst}]:{self.dport}'
121+
104122

105123
class PacketICMP(PacketIP):
106124
CODE_ECHO_REPLY = 0
@@ -133,5 +151,8 @@ def dump(self) -> dict:
133151
'icmp_code': self.icmp_code,
134152
}
135153

154+
def __repr__(self) -> str:
155+
return f'{self.src} ={self.proto_l4.N}-{self.icmp_code}=> {self._repr_ni()}{self.dst}'
156+
136157

137158
PACKET_KINDS = (PacketIP, PacketTCPUDP, PacketICMP)

0 commit comments

Comments
 (0)