wobblyhead

botblockd

Fight clankers with clankers

drawing of robots fighting
Robot Fight (c) 2026 M.A. Juszczyk

98% of internet traffic is bots.

Not always, not everywhere, of course. But when I was setting up my new server in early 2026, and transplanted a mildly popular website - afrofootball.com - from my old host in Switzerland, the move and refresh triggered a surge of new traffic that was, as far as I could tell, over 98% automated.

Indexers, scrapers, training data slurpers, incessant server probes. The server didn't really get stressed, a small-ish dedicated server at Hetzner with a FreeBSD root system, running everything in jails, rarely got over 10% system load. But still, the bot traffic drowned out signals from real humans, and, most grating, provided fodder for some of the most unethical companies in recent history.

As a first step, I've put Anubis in front of all the HTTP servers on the machine. My setup already has a central proxy for auth, TLS termination and statistics, so adding that was not a major thing. But Anubis on its own only blocks the bots at the application level, sending them off into a .well-known maze. Once you know a client is up to no good, why let it access the server at all?

FreeBSD has blocklistd, a daemon that can react to attack signals and block clients at the firewall, but it requires the service to explicitly tell it that it is being attacked; that works, with patches, for sshd, but not for nginx, especially when it's running in a separate jail. There is also fail2ban, that I used previously on company setups, but I'm not fond of its configuration and interface.

botblockd is my attempt to close that gap: it tails the aggregated http access logs from all the services on the machine, and tells pf, FreeBSD's default firewall, to block IPs of clients that trigger errors more often than not, or don't obey "back off, slow down" responses. Basically, it's the missing nginx-to-pf adapter. It's not effective against distributed attacks coordinated from many separate IPs. That would need a much bigger and more complex system, and I wasn't willing to go that far.

It's written in C, which makes it tiny: the binary is less than 25 kB. It has no external dependencies beyond what the base FreeBSD system provides.

The last time I was wrote C was in my Arduino1 tinkering phase, about ten years ago; before that it was some CGI scripts and code generators back in the nineties. I wanted a small, well-integrated system daemon, but didn't feel up to the task, not without spending more time than I had on catching up. So I turned it into an exercise in LLM-assisted development.

Initially, I thought that for a limited task like this, a locally running Qwen Coder instance would do. And if you break down the requirements into bite-sized chunks, are used to staring at progress bars, and have some2 patience, it can get quite far. It's not something that can look for bugs though, or evaluate different approaches, or judge correctness of the logic, or go far beyond calling out to shell processes. In the end I gave in and let Claude polish and beef up the code.

Claude has its own pitfalls. Let off the leash, it is prone to overengineering things incoherently, one part of the code defending against another. At one point I removed about 400 lines of code to replace them with a small shell script because an earlier model misinterpreted a requirement and a later model took the pre-existing code as set in stone. It also took some time to formulate the rules of interaction that reined in the model's desire to be your friend. I'm not a manager, I don't need to be told how great my questions and ideas are.

In the end, after several more passes of cleaning up the code and humanising the documentation, and a few months in production without any issues, I'm happy enough with my little daemon to publish it. The version is 0.4 because I may still reconsider the strict single purpose and the tie to the one true packet filter.

Claude never commented on the irony of using bots to block bots. But that may be just my agent rules forbidding non-technical value judgments.


  1. Nominally, Arduino code is C++, but for practical purposes it was plain C with some inline assembly and some C++ ceremony in the build process. ↩

  2. Well, quite a bit of patience. ↩