© 2017 Peter N. M. Hansteen
While preparing material for the upcoming BSDCan PF and networking tutorial1), I realized that the pop3 gropers were actually not much fun to watch anymore. So I used the traffic shaping features of my OpenBSD firewall to let the miscreants inflict some pain on themselves. Watching logs became fun again.
Note: This piece is also available with trackers but nicer formatting here.
Yes, in between a number of other things I am currently in the process of creating material for new and hopefully better PF and networking session.
I've been fishing for suggestions for topics to include in the tutorials on relevant mailing lists, and one suggestion that keeps coming up (even though it's actually covered in the existling slides as well as The Book of PF) is using traffic shaping features to punish undesirable activity, such as
Idea for pf tutorial: throttling of http abusers using pf and altq. /cc @pitrh @stucchimax— Dan Langille (@DLangille) April 16, 2017
bruteforce tables are never totally empty. queue spamd parent rootq bandwidth 1K min 0K max 1K qlimit 300
table <longterm> persist counters
table <popflooders> persist counters
block drop log (all) quick from <longterm> 
pass in quick log (all) on egress proto tcp from <popflooders> to port pop3 flags S/SA keep state \
(max-src-conn 1, max-src-conn-rate 1/1, overload <longterm> flush global, pflow) set queue spamd
pass in log (all) on egress proto tcp to port pop3 flags S/SA keep state \
(max-src-conn 5, max-src-conn-rate 6/3, overload <popflooders> flush global, pflow)
popflooders table, the flush global part means any existing connections that source has are terminated, and when they get to try again, they will instead match the quick rule that assigns the new traffic to the 1 kilobyte queue. quick rule here has even stricter limits on the number of allowed simultaneous connections, and this time any breach will lead to membership of the longterm table and the block drop treatment.longterm table I already had in place a four week expiry (see man pfctl for detail on how to do that), and I haven't gotten around to deciding what, if any, expiry I will set up for the popflooders.pfctl -vvsq shows the tiny queue works as expected: queue spamd parent rootq bandwidth 1K, max 1K qlimit 300
[ pkts: 196136 bytes: 12157940 dropped pkts: 398350 bytes: 24692564 ]
[ qlength: 300/300 ]
[ measured: 2.0 packets/s, 999.13 b/s ]Apr 19 22:39:33 skapet spop3d[44875]: connect from 111.181.52.216
Apr 19 22:39:33 skapet spop3d[75112]: connect from 111.181.52.216
Apr 19 22:39:34 skapet spop3d[57116]: connect from 111.181.52.216
Apr 19 22:39:34 skapet spop3d[65982]: connect from 111.181.52.216
Apr 19 22:39:34 skapet spop3d[58964]: connect from 111.181.52.216
Apr 19 22:40:34 skapet spop3d[12410]: autologout time elapsed - 111.181.52.216
Apr 19 22:40:34 skapet spop3d[63573]: autologout time elapsed - 111.181.52.216
Apr 19 22:40:34 skapet spop3d[76113]: autologout time elapsed - 111.181.52.216
Apr 19 22:40:34 skapet spop3d[23524]: autologout time elapsed - 111.181.52.216
Apr 19 22:40:34 skapet spop3d[16916]: autologout time elapsed - 111.181.52.216popflooders table had reached approximately 300. table <popflooders> persist counters file "/var/tmp/popflooders"popflooders table is dumped at five past every full hour to pop3gropers.txt, a file desiged to be read by anything that takes a list of IP addresses and ignores lines starting with the # comment character. I am sure you can think of suitable applications.pop3gropers_full.txt for readers who are interested in such things as when an entry was created and how much traffic those hosts produced, keeping in mind that those hosts are not actually blocked here, only subjected to a tiny bandwidth.[Wed May 17 19:38:02] peter@skapet:~$ doas pfctl -t popflooders -T show | wc -l 5239[Wed May 17 19:38:42] peter@skapet:~$ doas pfctl -t popflooders -T show | grep -c \: | wc -l77max-src-conn 1, max-src-conn-rate 1/1.table persist counters file "/var/tmp/bruteforce" block drop log (all) quick from <bruteforce>#-prepended comment at the start) suitable for importing into such things as a PF table you block traffic from, the address list with the country code for each entry appended, and finally a summary of list entries per country code. All varieties are generated twice per hour.
1) At EuroBSDcon 2025, there will be a Network Management with the OpenBSD Packet Filter Toolset session, a full day tutorial starting at 2025-09-25 10:30 CET. You can register for the conference and tutorial by following the links from the conference Registration and Prices page.