protection bundle

Every public IRC server is scanned within hours of going online. Botnets and drone networks connect by the hundreds to flood channels, spam users and probe for open proxies, and plain scanners open and drop sockets just to fingerprint you. The Protection bundle is SekurIRCd's answer: an optional layer, built into the daemon and configured from a single file, that stops most of this before a client ever registers. No external services, no extra processes.

It is a module you choose to run. Leave the file out and the daemon behaves as a plain ircd; drop it in and edit one place to tune all of it.

why it matters

the layers

LayerCatchesSection
Blacklists (DNSBL)Known open proxies, drones and spam hosts listed by a DNS blocklist[blacklist]
Proxy scannerOpen proxies nobody has reported yet, found by testing the connecting address[scanner]
Connection limitsOne host holding many sockets, total overload, and scanners that open and close sockets rapidly[connection]
Per-client flood guardRegistered clients sending too many lines too fast[flood]
Spam protectionAdvertising and mass-messaging bots that connect politely and then spam users or channels[spam], spamfilters.conf, SPAMFILTER
ExemptionsTrusted addresses that must never be checked or scanned[exempt]
K/G/Z-linesManual and automatic bans, with durations (K/G match host or user@host; Z is IP-only)KLINE GLINE ZLINE, klines_file

turning it on

The bundle is one file, protection.toml, kept next to sekurircd.toml. A fully commented template ships as config/protection.template.toml. tools/makeconf.py and the web wizard can write it for you from a few questions. To start from the template instead:

cp config/protection.template.toml /etc/sekurircd/protection.toml
$EDITOR /etc/sekurircd/protection.toml
/REHASH                              # no restart needed
/PROTECT                             # shows what is active

blacklists (dnsbl)

A DNSBL (DNS blocklist) is a DNS zone that answers "is this IP known-bad?". SekurIRCd reverses the connecting IPv4 address, looks up d.c.b.a.<zone> on a worker thread, and reads the answer's last octet, the reply code, which says why it is listed. Lookups never block the main loop: the new connection is simply held, with no input read, until the verdict arrives. IPv6 addresses are not checked, and a zone that does not answer fails open, so the connection is let through.

No zone is hardcoded, so a provider changing its policy can't surprise you. The template enables the EFnet RBL, an IRC-focused list of open proxies, drones and spamming hosts with no query-volume restrictions.

configure

[blacklist]
enabled = true
timeout = 5.0                 # seconds to wait before treating the address as "not listed"
action = "zline"              # "zline" | "kline" | "reject"
ban_duration = "1d"           # "1d", "12h", "30m", or seconds; "" = permanent

[[blacklist.zone]]
name = "rbl.efnetrbl.org"
type = "reply"                # "reply": last octet must equal a code below; "bitmask": bit test
ban_unknown = true            # listed with a code that is not below: ban anyway?
reason = "Blacklisted (%r) -- for more information, visit https://rbl.efnetrbl.org/?i=%i"
replies = ["1:open proxy", "2:spamtrap666", "3:spamtrap50", "4:TOR", "5:drones / flooding"]

To see whether an address is listed, reverse its octets and query the zone yourself: dig +short 4.3.2.1.rbl.efnetrbl.org checks 1.2.3.4. Any answer means listed; the last octet is the reply code.

proxy scanner

A blacklist only knows about proxies somebody already reported. The scanner finds the rest itself. When a client connects, the server opens connections back to that client's address on the classic proxy ports and asks each to relay to this server. If this server's own connect banner (*** Looking up your hostname) comes back through the relay, the address is a working open proxy: it is banned, and so is everyone connected from it.

ProbeWhat it does
httpHTTP CONNECT to this server. The most common open proxy, found on many ports.
httppostAn HTTP POST through a forward proxy. Sends one block of data, but enough of them still make a flood.
socks4SOCKS4 connect request.
socks5SOCKS5 with no authentication, then a connect request.

The scan runs in the background: the client registers and chats as normal until a scan confirms, so honest users never wait on it. It uses non-blocking sockets in the main event loop, not the worker threads, and is bounded three ways: a per-probe timeout, a max_concurrent cap on open probe sockets (a connection flood can't exhaust your file descriptors), and an optional negative cache so a clean address isn't rescanned.

[scanner]
enabled = false               # off by default
action = "zline"              # "zline" | "kline" | "reject"
ban_duration = "1d"
protocols = ["http:80", "http:8080", "http:3128", "http:6588", "httppost:80",
             "httppost:8080", "socks4:1080", "socks5:1080"]
timeout = 10.0
max_concurrent = 256
negcache = "0"                # e.g. "1h": skip addresses that just scanned clean

[scanner.target]
ip = "203.0.113.10"           # THIS server's PUBLIC address (required)
port = 6667

Before you enable it:

Scan an address on demand as an oper with /PROTECT SCAN <ip>.

connection limits

connect-flood throttle

Scanners often connect and drop faster than a concurrency cap can see. This tracks connections per IP over a time window; once an IP exceeds the limit it is banned automatically and told reconnecting too fast.

[connection]
connect_flood_max = 5                 # more than this many connects...
connect_flood_window = 10.0           # ...within this many seconds -> ban
connect_flood_ban_duration = "10m"    # "" = permanent; connect_flood_max = 0 disables the check

Raise connect_flood_max if many legitimate users share one NAT'd IP, such as a school, an office, or a web gateway like Kiwi in front of your server.

connection caps

[connection]
max_connections = 0            # total simultaneous connections; 0 = unlimited
max_connections_per_ip = 0     # per single IP; 0 = unlimited

Both default to unlimited. Set them on any public server; a per-IP cap of 3 to 5 suits most networks, higher if gateways or shared NATs front real users. Refused connections get a plain ERROR before registration.

per-client flood guard

[flood]
max_msgs = 20      # a registered client sending more than this many lines...
window = 1.0       # ...within this many seconds is disconnected

The guard counts every line alike. For what it lets through (scraping with WHO and LIST, WHOIS probing, nick changing), limit single commands:

[flood]
command_limits = ["WHO 5/10", "LIST 2/30", "WHOIS 10/10", "NICK 3/60"]   # at most 5 WHO per 10 seconds, ...

Past a limit the user is answered "Please wait a while and try again" (numeric 263) and the command is not run; nobody is disconnected. Opers are never held to them, NICK counts only once registered, and the key works in [security] of sekurircd.toml too.

When a server is under attack, /DEFCON (an oper command) raises the bar for new connections at once, and /DEFCON 5 lifts it: level 4 halves the connect rate and allows two connections per address, 3 also needs a login (SASL), 2 also needs TLS, 1 takes no new connections. An ELINE'd address is exempt. /DEFCON 3 30m puts the level back by itself.

bans: k-line, g-line, z-line

All three ban by IP mask, are enforced before registration, and disconnect matching clients that are already online. Automatic bans from blacklist hits, the proxy scanner and the connect-flood throttle are recorded as Z-lines (a pure-IP ban applied before registration), tagged with what set them: dnsbl, protection (the scanner) or connect-flood.

/ZLINE 198.51.100.7 1d :abuse from this host    # add: mask, optional duration, reason
/ZLINE                                          # no arguments: list active lines
/UNZLINE 198.51.100.7                           # remove
/STATS z                                        # also /STATS k, g, s (SHUN), e (ELINE), b (DNSBL + scanner)

KLINE/UNKLINE and GLINE/UNGLINE take the same arguments. Durations are 30m, 12h, 1d, or omit for permanent. Set [security] klines_file so bans survive REHASH and restarts; without it they live in memory only.

What each letter matches. ZLINE is enforced at accept(), before the client has sent anything, so it can only ever match the IP — that is why the blacklist, scanner and connect-flood auto-bans use it. KLINE and GLINE additionally match user@host, so *.example.com or bob@*.example.com do what they look like they do. Since a hostname isn't known until rDNS/ident finish, a host mask is checked again at the end of registration rather than at connect time. The ident is tried both bare and ~-prefixed, so a mask bites whether or not identd answered.

False positives: a legitimate user who is on a DNSBL can be freed with UNZLINE, but their next connection triggers a fresh lookup and bans them again, unless the address is under [exempt]. The reliable fixes are that exemption, dropping the zone, narrowing it with replies and ban_unknown = false, or using action = "reject" so no lasting ban exists and pointing the user at the provider's delisting page, which is what %i in the ban reason is for.

Exempting an address live: [exempt] only skips the DNSBL and the scanner and needs a rehash. An ELINE on an IP, glob or CIDR (/ELINE 2402:d0c0:21::/64 1d :our bouncers) takes effect at once and exempts that address from Z-lines, the connect-flood throttle, the per-IP connection cap, the DNSBL and the scanner as well, so a trusted network that reconnects fast is never banned. It lives on that server only (like the connect-flood throttle it overrides), shows in /STATS e and TESTLINE, and goes with /UNELINE <mask>. Lifting a connect-flood ban with UNZLINE also forgets that address's connect count, so the next connection isn't banned again at once.

spam protection

The layers above act on connections. [spam] acts on what a connected user sends. It is off by default (enabled = false); when off, none of it runs. It has three independent layers:

  1. New-connection restriction. A fresh connection cannot PM users for new_user_period (default 30s). Channels stay open, and anyone can always message services and opers, so nobody is locked out of asking for help.
  2. Content filters. Regex rules from filters_file (an annotated example ships as config/spamfilters.template.conf; the live spamfilters.conf is created from it) are matched against PRIVMSG/NOTICE to users and channels, and against AWAY, QUIT, PART and TOPIC text. Matching is case-insensitive POSIX ERE, run after mIRC colour and bold codes are stripped.
  3. Recipient and repeat limits. Messaging more than max_targets different people or channels, or sending the same text (8+ characters) to max_repeat of them, inside target_window triggers limit_action.
[spam]
enabled = true
exempt_opers = true          # opers and services are never checked
exempt_identified = true     # neither is anyone logged in to an account
new_user_period = "30s"      # "0" = off
max_targets = 5              # distinct recipients per target_window; 0 = off
target_window = "30s"
max_repeat = 4               # same text to this many recipients; 0 = off
limit_action = "block"       # block | warn | kill | zline | hide | shun
zline_duration = "1h"
trust_age = "0"              # connections older than this skip the limits (not the filters)
filters_enabled = true       # false keeps the file but stops using it
filters_file = "spamfilters.conf"

filter rules

One rule per line: [global] <targets> <action> <duration|-> "<reason>" <regex>. Targets are letters: p PRIVMSG to a user, c PRIVMSG to a channel, n/N NOTICE to a user/channel, a AWAY, q QUIT, P PART, t TOPIC. The first matching rule wins.

ActionEffect
blockDrops the message and tells the sender. QUIT and PART reasons are silently replaced with a blank one.
warnDelivers the message but notifies opers. Use it to trial a rule before enforcing it.
killDisconnects the sender.
zlineDisconnects the sender and Z-lines their IP for the rule's duration (- means zline_duration).
hideSilently drops the message: no notice to the sender, and echo-message clients get their own line back so it looks delivered. Opers are still notified.
allowDelivers the text untouched and skips every rule below it: an exception to a broader rule, or to a global one.
shunLike hide, and also SHUNs *@ip network-wide for the rule's duration (- means zline_duration): the sender stays connected but nothing they send reaches anyone.
pcnN block - "advertisement" (buy|cheap) +(viagra|followers|likes)
pc warn - "possible invite spam" (join|server) .*(discord\.gg|t\.me)
qPt zline 1h "advertising in reason" https?://[^ ]+.*(casino|porn)

managing rules live

/SPAMFILTER                                   # list rules (with numbers) and the hit counter
/SPAMFILTER ADD pc block - ad_spam :cheap +viagra
/SPAMFILTER ADD GLOBAL pcnN shun 1d hosting_advert :vps.*promo
/SPAMFILTER DEL 3

ADD takes targets, action, duration, a reason (underscores become spaces) and the regex, and appends to the filters file. DEL removes the numbered rule from the file and leaves your comments alone. Regexes with backreferences, or that match the empty string, are refused. Editing the file by hand and running /REHASH reloads it; a line that fails to parse is skipped with a logged warning. If filters_file = "", rules exist in memory only.

global rules

Rules apply to the users connected to the server that runs them, so a spammer on a leaf that lacks a rule is not stopped by the hub having it. A rule that starts with global in spamfilters.conf, or is added with /SPAMFILTER ADD GLOBAL, is sent to every linked server, and each enforces it as if it were its own. Add them on the hub and every leaf has them.

Global rules from other servers are kept in memory, not on disk, and come back with the link. If the hub is down when a leaf restarts, the leaf has none of them until it links again. A server that has gone for good leaves its rules on the others until they restart; /SPAMFILTER DEL removes them from the server you are on.

Scope: enforcement covers this server's own users, with each linked server enforcing its own filters file plus the global rules it was sent. Every action sends opers with +s a notice that includes the offending text, which is the easiest way to tune rules and limits.

monitoring

server notices

Opers get user mode +s automatically on /OPER and receive a notice for every refused connection, for example Rejected connection from 203.0.113.9: Blacklisted (drones / flooding) ..., and for every ban added, removed or expired. If it gets noisy during an attack, silence it with /MODE <yournick> -s.

/PROTECT

/PROTECT                 # server opers: what is active, and the counters
/PROTECT SCAN 203.0.113.9

Prints the bundle file in use, the blacklists (zones, action, hits so far), the scanner (probes per client, target, in flight, scanned, proxies found, negcache size), the connection limits, the flood guard and spam protection.

debug channel and log

The bundle needs no notification setup of its own. Everything it does is logged, and the [debug_channel] you already have relays it, so #server-debug doubles as its live feed:

[debug_channel]
enabled = true
name = "#server-debug"      # oper-only; JOIN is refused to everyone else
min_level = "INFO"          # bans are WARNING, the startup summary and stats lines are INFO
stats_interval = 300        # seconds between summary lines
WARN protection 203.0.113.9 is an open socks5 proxy (port 1080) -- Z-lined for the configured duration, 3 client(s) disconnected
WARN dnsbl 203.0.113.44 listed in rbl.efnetrbl.org (drones / flooding) -- Z-lined
protection scanner: 8 probe(s) per client [http:80 ... socks5:1080], target 198.51.100.7:6667, action=zline, negcache 3600s, max 256 in flight
WARN protection scanner.target.ip 10.0.0.5 is a private address -- proxies on the internet can't reach it ...

The startup summary is logged at start and after every /REHASH, so you can confirm what a reload actually turned on. With stats_interval set, the periodic summary tells you how well protection is working (example output):

stats users 142 (peak 190) | channels 61 (18 registered) | connections 9314 | bans K0 G0 Z38 (35 DNSBL, 3 scanner)
      | DNSBL hits 412 | scanner 8817 scanned, 3 proxies, 2 in flight, 641 cached | spam filter 27 actions, 14 rules
      | ircd 0.4% cpu 21MB | sekurircd 1.3.6

Watch DNSBL hits, proxies and the count of active lines from each: a steady trickle is normal, and a sudden climb means an attack is being absorbed. If the hit count stays at zero on a public server for weeks, check that the zone still resolves with dig. Per-probe detail (log_all_scans) goes to the log file at DEBUG, deliberately not to the channel.

The stats panel keeps these numbers for every server and charts them per day.

recommended setup

# protection.toml
[exempt]
ips = ["127.*"]

[connection]
max_connections_per_ip = 4
connect_flood_max = 5
connect_flood_window = 10.0
connect_flood_ban_duration = "10m"

[blacklist]
enabled = true
action = "zline"
ban_duration = "1d"

[[blacklist.zone]]
name = "rbl.efnetrbl.org"
ban_unknown = true
replies = ["1:open proxy", "2:spamtrap666", "3:spamtrap50", "4:TOR", "5:drones / flooding"]

# sekurircd.toml
[security]
klines_file = "klines.json"          # persist bans across restarts

[debug_channel]
enabled = true
min_level = "INFO"
stats_interval = 300

Apply with /REHASH. Then open a client as an oper, join #server-debug, and confirm the summary line shows up. Add the [scanner] once you have read the notes above and know your public address. See the configuration page and the full template on GitHub for every key.