mastouille.fr est l'un des nombreux serveurs Mastodon indépendants que vous pouvez utiliser pour participer au fédiverse.
Mastouille est une instance Mastodon durable, ouverte, et hébergée en France.

Administré par :

Statistiques du serveur :

648
comptes actifs

#pf

0 message0 participant0 message aujourd’hui

After 20 years of using #pf on #BSD and only dabbling in iptables when I absolutely had to in #Linux, nftables looks like an unreadable, incomprehensible shitshow; A crayon scrawl by a toddler of weird nat and mangle chains that make no sense.

The Linux developers would have been much better off porting pf to Linux.

Over the past few weeks I have been switching off of NixOS and going back to the previous OSes and distros I was using. Last week I migrated my VPS back to OpenBSD and I now feel like I can appreciate its simplicity even more. That's not the point of this though.

When migrating I was reminded of something @nemo@camp.crates.im previously said about only allowing ssh access to the IP addresses he know he uses. I thought I should try doing something similar especially because to me pf is way saner to use and manage than iptables.

The addresses I know I'll use are my home IPv4 address and the IPv4+6 addresses of the Mullvad enpoints I am likely to use.
Unfortunately I don't know what those public addresses are before connecting.

A quick script containing something like below (I didn't save it >_<) later, I was able to get all the addresses I needed for passing to pf.
for i in *.conf; do
wg-quick up $i
curl -s4 https://zx2c4.com/ip | sed 1q
# the connect timeout is there because a few of the endpoints had a not-working IPv6 address
curl --connect-timeout -s6 https://zx2c4.com/ip | sed 1q
wg-quick down $i
done
```

Now in my pf.conf I just had to do something like this which didn't seem that complicated after all. I just modelled it after my existing rule that I used for opening ports (I removed ssh from that rule in favour of this one). This can most definitely be made better, but at least it works!

explicitly allow home and vpn ip addresses

ssh_whitelist_ipv4 = "{

ipv4 addresses here

I put my home address at the top as is and then /24 ranges for the mullvad IPs because I was told they may change frequently

}"
ssh_whitelist_ipv6 = "{

ipv6 addresses here from mullvad

I figured that they won't change often so I simply pasted them as is without specifying prefix

}"

...

allow public ssh only to my normal home address and mullvad ips

pass in log on $ext_if inet proto tcp from $ssh_whitelist_ipv4 to ($ext_if) \
port ssh flags S/SA keep state
pass in log on $ext_if inet6 proto tcp from $ssh_whitelist_ipv6 to ($ext_if) \
port ssh flags S/SA keep state

After running for over a day, my /var/log/authlog still only shows my own connections and not some people across the globe spamming connections to invalid users.

saklas$ zgrep preauth /var/log/authlog.0.gz | grep -v vin | wc -l
3918
saklas$ grep preauth /var/log/authlog | grep -v vin | wc -l
1

I was previously using pf-badhost in place of fail2ban due to the latter not being available on OpenBSD, but pf-badhost didn't prevent active attacks while both of them still allowed those (initial) connections in the first place.
There's a much smaller likelihood of an attacker using the same Mullvad endpoints I use, and if they do I probably have bigger problems to worry about. I'm also pretty much always connected to my Wireguard VPN (separate post on my website for this later) and that would let me bypass this anyways. This setup is more of a failsafe if I'm unable to connect through the VPN, and a failsafe of that failsafe if things really go wrong is just using the Hetzner web console I guess.

After writing all this, I think it's better to just post this on my website and syndicate here.

#openbsd #mullvad #pf
Comparing firewall syntax for SSH (port 22) with default-deny:
================================================

#iptables (Linux)
iptables -A INPUT -p tcp --dport 22 -j ACCEPT
iptables -P INPUT DROP

#nftables (Linux)
nft add rule inet my_filter input tcp dport 22 accept
nft add rule inet my_filter input drop

#ufw (Linux - simplified frontend to iptables)
ufw allow 22/tcp
ufw default deny incoming

#pf (OpenBSD)
pass in proto tcp to port 22
block all

pf’s syntax feels so elegant, human-readable, & minimal!

After 20years scripting iptables, I’m ready to try UFW on my laptop.
#firewall #sysadmin #pf #iptables #ufw #nftables

What do the clever OpenBSD firewall folks use to put up a reasonable defence against known bad actors?

I have an SSH bastion host that gest spammed with connection attempts (it only accepts key authentication but even so...) as well as web server for my blog that gets requests for dot files, PHP, cpanel, etc...

On both I'm currently running a shell script that greps the logs for keywords and feeds those IP's into a temporary blocklist but I'm sure there must be a better way, plus some way to feed in a reputable source of bad IP's before they become a problem would be nice.

Toc-toc #freebsd guys ! I created a bridge0 and Vnet running tailscale into #bastillebsd jail. Bridge and Vnet are connected using epair. I read on forum that rules from #pf operate on epair and not bridge, so I need to skip bridge0 in #pf rules ? Bridge0 is 193.168.42.1 connected with re0. Another thing, I want to separate/isolate my local network (192.168.1.0) from jails vnet network 192.168.42.0/24. Actually when I ping a local network address like 193.168.1.80 from the tailscale jail with epair 192.168.42.2, ping works... Isolation between networks don't work by default, and I search the good pf rules to isolate 192.168.42.0 from local network ... Any help appreciated.

Finally run debian12 with gui thanks to vm-bhyve on freebsd14 after several month of tweaking and learning. Really big thank to @vermaden and his article vermaden.wordpress.com/2023/08 ❤️

But one thing I still dont get it. I have a problem with resolving a DNS on the VM. IP addreses works well but domain names like google.com not at all. I solved it by adding "nameserver 8.8.8.8" in /etc/resolv.conf in VM, but I am not sure if I solve it well and dont understabd why I have to solve it anyway, I do not remeber that I would have to set it.
I se vm-bhyve with host wifi wlan interface so I had to set NAT in PF, in article it is a section laptop wifi nat. Is it normal to set resolv.conf file in VM?

𝚟𝚎𝚛𝚖𝚊𝚍𝚎𝚗 · FreeBSD Bhyve VirtualizationThe Bhyve FreeBSD hypervisor (called/spelled ‘beehive’ usually) was created almost 10 years ago. Right now it offers speed and features that other similar solutions provide – such…
#freebsd#bhyve#debian

Es geht weiter in meiner Artikelreihe: #FreeBSD als Server. Alle bisherigen Artikel wurden nochmal an einer frischen Installation durchgespielt und hier und da kleinere Anpassungen vorgenommen. Netzwerk Einstellungen und #pf Firewall hinzugefügt.

bsdbox.de/blog/2024-12-01-free

Mit Teil 4 kommt dann offiziell Bastille dazu. Bleibt dran.

bsdbox.deArtikelreihe: FreeBSD als Server. Teil 3 | BSDbox.Dieser Server dient uns als eine Informations- bzw. Austauschs-Plattform für alle Menschen, die sich konstruktiv und kreativ mit den Themen FreeBSD, LINUX, IT-Sicherheit und allgemeinen Netzwerkthemen befassen und austauschen möchten.

A piece of oft-repeated #openbsd #pf advice, from this morning on openbsd-misc:

In addition to the official resources such as the PF FAQ (openbsd.org/faq/pf/index.html) I think my own writings such as "A Few of My Favorite Things About The OpenBSD Packet Filter Tools" nxdomain.no/~peter/better_off_ (or with G's trackers
as the cost for slightly nicer formatting bsdly.blogspot.com/2022/09/a-f)
which has a few useful links at the end including to a certain book that *might*
be worth looking into.

www.openbsd.orgOpenBSD PF: User's Guide