I have a small VPS with FreeBSD and a bunch of jails with various services. Recently I stumbled upon a guide to aggressively block scanners, bots, etc. in order to proactively prevent them from even finding the moved ports for critical services like SSH, IMAP, submission, etc. I have to note that the simple measure to move the ports to non-standard ones almost completely eliminated junk traffic in logs (well, it's a small VPS).
But my patchy and rather superficial knowledge of networking in general, and firewalling in particular, makes me worry if I have really achieved what I have intended to. As I understand, the "
Basically, I would like to learn from the opinion of the experienced fellows if such a setup is a good thing. And if is not, what is a better alternative? Oh, a sideway question: which port does the
Here is an excerpt from /etc/pf.conf:
But my patchy and rather superficial knowledge of networking in general, and firewalling in particular, makes me worry if I have really achieved what I have intended to. As I understand, the "
synproxy state
" directive along with " pass in on $if_ext
" basically open the range of ports from the outside. And this is where I am becoming confused. My concerns are that some services I running without access from the outside (like net-mgmt/prometheus2 and some its exporters, for instance) actually listen to on ports in the range. So, I wonder, if I make my defence actually worse than just blocking all incoming traffic and employ blacklistd/fail2ban for buggers on specific ports.Basically, I would like to learn from the opinion of the experienced fellows if such a setup is a good thing. And if is not, what is a better alternative? Oh, a sideway question: which port does the
pkg
use to communicate with FreeBSD servers? I mean if I block outgoing traffic, which port should I open?Here is an excerpt from /etc/pf.conf:
Code:
#
################## 1. Macros
#
if_ext="vtnet0"
minefield = "1024:9999"
#
################## 2. Tables
#
#table <me> const file "/etc/trusted"
table <troublemakers> persist
table <rfc6890-in> { 0.0.0.0/8 127.0.0.0/8 100.64.0.0/10 169.254.0.0/16 172.16.0.0/12 \
192.168.0.0/16 192.0.2.0/24 240.0.0.0/4 255.255.255.255 }
table <rfc6890-out> { 0.0.0.0/8 100.64.0.0/10 169.254.0.0/16 172.16.0.0/12 192.168.0.0/16 \
192.0.2.0/24 192.0.2.0/24 240.0.0.0/4 255.255.255.255 }
#
################## 6. Translation
#
# Allow outbound connections from within the jails
nat on $if_ext from lo1:network to any -> ($if_ext)
##### 7. Redirection
# nginx as reverse proxy jail
rdr on $if_ext proto tcp from any to $ip_pub port { http, https } -> $ng_pr
# redirect to Mail Server
rdr on $if_ext proto tcp from any to $ip_pub port { sieve2, submission2, imaps2, smtp } -> $mail
#
################## 8. Packet filtering
#
anchor "blacklistd/*" in on $if_ext
anchor "f2b/*" in on $if_ext
########### Block unroutable addresses
block in quick on $if_ext from <rfc6890-in> to any
block return out quick on $if_ext from any to <rfc6890-out>
block quick proto tcp from <troublemakers> to any
block in
pass quick from lo0 to lo0
# Filtering loopback traffic in jails
pass quick from $ng_pr to $ng_pr
pass quick from $mds to $mds
...
pass quick from $dns to $dns
pass quick from $mail to $mail
pass out
#
########### Allow access to external IP
#
# Tagging scanners and bots
# These are just randomly probing port 22, 587, 993 is a dead-giveaway
# because we know we moved our service ports elsewhere
# Also, we have no telnet or SMB so anyone poking there is up to no good
# Tag stuff in the range $minefield as trouble as well
pass in on $if_ext proto tcp to $if_ext port { telnet, ftp-data, ftp, 22, pop3, \
rpcbind, imap, netbios-ns, netbios-ssn, microsoft-ds, 465, 993, 995, $minefield } \
synproxy state tag trouble
# Allow ICMP
pass in inet proto icmp to $if_ext icmp-type $icmp_types
# Allow ssh
pass in on $if_ext proto tcp to $if_ext port ssh2 tag good
pass out on $if_ext proto tcp to $if_ext port ssh2 tag good
# Allow access to the nginx proxy
pass in on $if_ext proto tcp to $ng_pr port { http, https }
# Allow access to the mail server
pass in on $if_ext proto tcp to $mail port { smtp, sieve2, submission2, imaps2 } tag good
# Put the troublemakers in the the corresponding table
pass proto tcp from any to $if_ext port { $sshd_port, $mail_tsl, $imap, $sieve, $sth_port, $minefield, \
telnet, ftp-data, ftp, 22, pop3, rpcbind, imap, netbios-ns, netbios-ssn, microsoft-ds, 465, 993, 995 } \
tagged trouble synproxy state \
(max-src-conn 1, max-src-conn-rate 1/1000, overload <troublemakers> flush global)
#
########### Allow access between jails
#
# Allow access local DNS cache server
pass quick proto { tcp, udp } from { lo0, lo1 } to $dns port 53
# Allow local mail to the mail server
pass quick proto tcp from { lo0, lo1 } to $mail port smtp
# Allow nginx proxy trafic to jails
pass quick proto tcp from $ng_pr to { $ap, $lib, $rss, $cal } port { http, 81, 8080, 8081 }
...