/etc/pf.badhosts:/etc/pf.goodhosts:/etc/pfctl.conf extract:
table <badhosts> persist file "/etc/pf.badhosts"
block on $int_if from <badhosts> to any
# '/etc/pf.goodhosts' will override any accidental blocks on '/etc/pf.badhosts' (e.g: Your LAN subnet.).
table <goodhosts> persist file "/etc/pf.goodhosts"
pass on $int_if from <goodhosts> to any
# pfctl -t badhosts -T show
# pfctl -t badhosts -T add <ip>
# pfctl -t badhosts -T delete <ip>
# pfctl -t badhosts -T replace -f /etc/pf.badhosts
pf.conf.
# Variables.
int_if="vio0"
...
## In.
# Block and log all packets except rules following.
block log all
# Allow IPv4 ICMP-echo(8) traffic, log and rate-limit.
pass in log on $int_if inet proto icmp all icmp-type echoreq keep state (max-src-conn 50, max-src-conn-rate 10/30, overload <abusive_hosts> flush)
# Allow IPv4 SSH traffic on tcp, log and rate-limit.
pass in log on $int_if inet proto tcp from any to $int_if port { 22 } flags S/SA keep state (max-src-conn 50, max-src-conn-rate 10/30, overload <abusive_hosts> flush)
# Allow IPv4 HTTP and HTTPs traffic on tcp, log and rate-limit.
pass in log on $int_if inet proto tcp from any to $int_if port { 80, 443 } flags S/SA keep state (max-src-conn 100, max-src-conn-rate 20/10, overload <abusive_hosts> flush)
## Allow all outbound traffic.
pass out all
...
## Tables.
table persist
block in on $int_if from to any
For UDP, it is the same pass in log on $int_if inet..... rule except you omit flags S/SA (as they are not used in UDP packets) and swap inet proto tcp for inet proto udp.
For example:
pass in log on $int_if inet proto udp from any to $int_if port { 8080 } keep state (max-src-conn 100, max-src-conn-rate 20/10, overload <abusive_hosts> flush)
<abusive_hosts> table and remove any duplicate IPs from the file
#!/bin/ksh
## Crontab: 0 */4 * * * /etc/pf.abusive_hosts.sh
pfctl -t abusive_hosts -T show >> /etc/pf.abusive_hosts
pfctl -t sshguard -T show >> /etc/pf.abusive_hosts
sort -u /etc/pf.abusive_hosts > /etc/pf.abusive_hosts2
cp /etc/pf.abusive_hosts2 /etc/pf.abusive_hosts
rm -f /etc/pf.abusive_hosts2
pf.conf.
# Block nmap's OS detection scanning.
block in log quick proto tcp flags FUP/WEUAPRSF
block in log quick proto tcp flags WEUAPRSF/WEUAPRSF
block in log quick proto tcp flags SRAFU/WEUAPRSF
block in log quick proto tcp flags /WEUAPRSF
block in log quick proto tcp flags SR/SR
block in log quick proto tcp flags SF/SF