2024-11-20 18:15:48 +01:00
|
|
|
#
|
|
|
|
|
# Look at past logs tcpdump -n -e -ttt -r /var/log/pflog
|
|
|
|
|
# Look at live logs (aka tail -f): tcpdump -n -e -ttt -i pflog0
|
|
|
|
|
#
|
|
|
|
|
# Look at entries in table <bad_hosts> (SSH Limit Block):
|
|
|
|
|
# pfctl -t bad_hosts -T show
|
|
|
|
|
# Delete an ip from table:
|
|
|
|
|
# pfctl -t bad_hosts -T delete $ip
|
|
|
|
|
|
2024-11-08 20:08:56 +01:00
|
|
|
ext_if="{{ ansible_default_ipv6.interface }}"
|
2024-11-21 19:38:55 +01:00
|
|
|
jail_net="{{ jailnet.stdout }}"
|
2024-11-08 20:08:56 +01:00
|
|
|
|
|
|
|
|
### Default block policy is to return a reset packet
|
2024-11-20 18:15:48 +01:00
|
|
|
set block-policy drop
|
|
|
|
|
|
|
|
|
|
# fairness my ass
|
|
|
|
|
set optimization aggressive
|
|
|
|
|
|
2024-11-08 20:08:56 +01:00
|
|
|
### Reassemble fragmented packets
|
|
|
|
|
scrub in on $ext_if all fragment reassemble
|
2024-11-20 18:15:48 +01:00
|
|
|
|
2024-11-08 20:08:56 +01:00
|
|
|
### Ignore loopback interface
|
|
|
|
|
set skip on lo
|
|
|
|
|
|
|
|
|
|
### Allow empty table to exist
|
|
|
|
|
table <jails> persist
|
|
|
|
|
|
|
|
|
|
### Block on incoming traffic
|
2024-11-20 18:15:48 +01:00
|
|
|
block in log all
|
2024-11-08 20:08:56 +01:00
|
|
|
|
|
|
|
|
### Allow outgoing, skip others rules if match, and track connections
|
|
|
|
|
pass out quick keep state
|
2024-11-20 18:15:48 +01:00
|
|
|
pass out inet6 keep state
|
2024-11-24 13:12:51 +01:00
|
|
|
|
|
|
|
|
# FIXME: does not survice reboots, that is: pf blocks after a reboot, pf must be reloaded, then it works
|
2024-11-21 19:38:55 +01:00
|
|
|
pass out quick on $ext_if keep state
|
|
|
|
|
pass out on $ext_if inet6 keep state
|
|
|
|
|
|
|
|
|
|
### Allow traffic coming from jails
|
|
|
|
|
pass in on $ext_if inet6 from $jail_net keep state
|
2024-11-08 20:08:56 +01:00
|
|
|
|
|
|
|
|
### Block all incoming traffic from the $ext_if subnet which is not from $ext_if interface
|
|
|
|
|
### And block incoming traffic from $ext_if IP on $ext_if interface
|
|
|
|
|
antispoof for $ext_if inet6
|
|
|
|
|
|
|
|
|
|
### Allow SSH
|
2024-11-20 18:15:48 +01:00
|
|
|
table <bad_hosts> persist
|
|
|
|
|
pass in quick on $ext_if inet6 proto tcp from any to any port ssh \
|
|
|
|
|
flags S/SAFR keep state \
|
|
|
|
|
(max-src-conn-rate 10/60, \
|
|
|
|
|
overload <bad_hosts> flush global) label ServicesTCP
|
|
|
|
|
|
2024-11-21 19:38:55 +01:00
|
|
|
# allow ansible answers
|
|
|
|
|
pass out on $ext_if proto tcp from port 22 to any flags any
|
|
|
|
|
|
2024-11-20 18:15:48 +01:00
|
|
|
# ipv6 icmp
|
|
|
|
|
pass in quick inet6 proto icmp6 all keep state
|