The story of an attack
This follows one attack from the first wrong password to the end of the ban, and explains what every part of ipfence does at each moment.
All output here was recorded from a real run on a disposable Debian 13 virtual
machine. The attacker was simulated from an isolated network inside that machine.
Long output is shortened where marked ....
| Role | Address |
|---|---|
| Your server | 203.0.113.1 |
| The attacker | 203.0.113.50 |
| An ordinary visitor | 203.0.113.60 |
| You, administering over SSH | 10.0.2.2 |
Cast of parts
Diagram source
flowchart LR
SSHD["sshd"] -->|writes| J[("journal")]
J -->|journalctl| R["reader"]
R -->|events| E["engine: policy"]
E <-->|memory| DB[("SQLite")]
E -->|"desired state"| F["firewall code"]
F -->|netlink| K[["kernel: nftables"]]
CLI["you: ipfence status"] -->|Unix socket| EAct 0: before installing protection
You run:
Terminal session
$ sudo ipfence init
ipfence init: local discovery report (nothing in the firewall was changed)
SERVICE DETECTED SOURCE PARSER PACKET PATH WILL ACTIVATE
ssh yes yes yes yes yes
nginx yes yes unknown unknown no
caddy yes no unknown unknown no
...
Allowlist
Allowlisting 10.0.2.2 (that exact address only, from the open SSH session running this command)
Config
created /etc/ipfence/config.toml:
[allow]
addresses = ["10.0.2.2"]What happened inside:
- ipfence looked at which services systemd knows about, which programs are running, which of them are listening, and whether it can read the journal.
- For each service it asked four questions. Is it detected? Can its events be read (source)? Is the format understood (parser)? Would a ban affect the way its traffic arrives (packet path)? Only four "yes" answers activate a detector.
- It noticed you were connected over SSH from
10.0.2.2, confirmed that connection really was open, and wrote that single address into a new settings file so you cannot be banned. - It changed nothing in the firewall.
Act 1: the daemon starts watching
Terminal session
$ sudo systemctl enable --now ipfenceThe service log shows:
Plain text
level=INFO msg="detector active" service=ssh source="journald through journalctl (20 recent sshd entries seen)"
level=INFO msg=ready version=0.1.0Behind the scenes ipfence started this helper to follow the journal (visible in
systemctl status ipfence):
Plain text
/usr/bin/journalctl --follow --no-tail --no-pager --quiet --output=json
--output-fields=MESSAGE,_SYSTEMD_UNIT,_EXE,_COMM,_UID --since=@1795919538
_COMM=sshd _COMM=sshd-session _COMM=sshd-authIn words: "give me, as structured data, messages from any of the three SSH programs, starting ten minutes ago, and keep sending new ones".
Status now says observing only:
Plain text
Daemon running (pid 1083, version 0.1.0, since 2026-11-29 02:42:18 UTC)
Enforcement disabled: observing only, nothing is blocked
Firewall (nftables table inet ipfence)
ownership: absentAct 2: three wrong passwords
The attacker tries root three times. sshd writes:
Plain text
2026-11-29T02:42:23+00:00 ipfence-final sshd-session[1110]: Failed password for root from 203.0.113.50 port 53585 ssh2
2026-11-29T02:42:25+00:00 ipfence-final sshd-session[1116]: Failed password for root from 203.0.113.50 port 33135 ssh2
2026-11-29T02:42:27+00:00 ipfence-final sshd-session[1122]: Failed password for root from 203.0.113.50 port 49681 ssh2What ipfence actually receives is richer:
JSON
{
"MESSAGE": "Failed password for root from 203.0.113.50 port 53585 ssh2",
"_COMM": "sshd-session",
"_EXE": "/usr/lib/openssh/sshd-session",
"_UID": "0",
"_SYSTEMD_UNIT": "ssh.service",
"__CURSOR": "s=7ad53dcc...;i=1727;b=3714...",
"__REALTIME_TIMESTAMP": "1795920143110045"
}Step 1: is it genuine?
_COMM is an SSH program, _UID is 0 (root), and _EXE is the real binary in a
system folder. Genuine.
A forger running logger -t sshd "Failed password for root from 203.0.113.60 ..."
would produce _COMM = logger and their own user number. ipfence would count it
as journal.untrusted and do nothing.
Step 2: what does it say?
The message matches the "failed password" pattern. ipfence takes the address from
the end of the message, because the user name in the middle is chosen by the
attacker. Someone logging in as x from 6.6.6.6 port 22 ssh2 produces:
Plain text
Failed password for invalid user x from 6.6.6.6 port 22 ssh2 from 203.0.113.50 port 4 ssh2The genuine address is the last one.
The result is a small event: service ssh, kind failed-password, address
203.0.113.50, a time, one point, and the cursor as its identity. The user name
is thrown away here and never stored.
Step 3: should this address be counted at all?
ipfence checks, in order: is it unusable, loopback, one of this server's own addresses, allowlisted, a trusted proxy, or private? None apply.
Is it already banned? No. Is the event older than ten minutes, or older than a ban already served? No.
Step 4: remember it
One hit is written to the database, in the same transaction as the new bookmark. Status shows:
Plain text
Local counters (persisted in the database since it was created)
events.counted 3
events.seen 3Three points. The threshold is five. Nothing else happens.
Interlude: testing a line yourself
You can ask what ipfence would make of any line, with no side effects:
Terminal session
$ sudo ipfence test "Failed password for root from 203.0.113.50 port 40022 ssh2"
dry run: the database and firewall were not touched
service: ssh
result: failure matched (failed-password)
address: 203.0.113.50 (global)
confidence: normal
would count: yes: counts toward a ban at 5 within 10m
$ sudo ipfence test "Invalid user admin from 192.168.1.50 port 22"
...
would count: no: private and link-local addresses are not banned automatically (policy.auto_ban_private)Act 3: the fifth failure, in observe mode
Two more attempts. The score reaches five, and:
Plain text
level=INFO msg=decision event=observe address=203.0.113.50 service=ssh reason="5 SSH authentication failures within 10m (latest: failed-password)"Plain text
Would have banned, observed only (1)
ADDRESS ORIGIN SERVICE OFFENSE EXPIRES IN IN FIREWALL REASON
203.0.113.50 auto ssh 1 14m 58s no (observed) 5 SSH authentication failures within 10m (latest: failed-password)The firewall is untouched (nft list ruleset printed nothing) and the attacker can
still reach the server:
Plain text
64 bytes from 203.0.113.1: icmp_seq=1 ttl=64 time=0.014 ms
1 packets transmitted, 1 received, 0% packet lossThis is deliberate. You get to see ipfence's judgement before giving it power. Even a manual ban is refused here, rather than pretending to work:
Terminal session
$ sudo ipfence ban 203.0.113.99 --for 1h
ipfence: refused: enforcement is disabled, so this ban would block nothing; run "ipfence enable" firstAct 4: you enable enforcement
Terminal session
$ sudo ipfence enable
enforcement is enabled
ipfence now owns the table inet ipfence: one input chain at priority -10, policy accept,
holding rules that only drop packets whose source is banned and not allowlisted.
No other table is changed.
Recovery, from a console or an allowlisted address:
ipfence unban <address> remove one ban
ipfence allow <address> never block an address
ipfence disable --yes remove all ipfence firewall rules
nft delete table inet ipfence the same, without ipfenceThe earlier "would have banned" entry is closed, not turned into a real ban. Only things that happen from now on count.
What was created, line by line
The kernel's listing from the test machine, shortened, with # comments added:
Plain text
table inet ipfence { # ipfence's own table, for IPv4 and IPv6
set ban4 { # single banned IPv4 addresses
type ipv4_addr
flags timeout # entries may expire on their own
}
set ban4net { ... interval,timeout } # banned IPv4 ranges
set ban6 { ... } # the same two for IPv6
set ban6net { ... }
set allow4 { # never dropped
type ipv4_addr
flags interval
elements = { 10.0.2.2, # you (from the settings file)
10.0.2.15, # this server's own addresses ...
10.200.0.1,
127.0.0.0/8, # loopback
172.17.0.1, 203.0.113.1 }
}
set allow6 { ... }
chain owner_v1_f9ccab8da636ed7a28c6dfb729244c3f {
} # empty: it only says "this table is mine"
chain input {
type filter hook input priority filter - 10; policy accept;
iifname != "lo" ip saddr @ban4 ip saddr != @allow4 counter drop comment "ipfence:v1:input:ban4"
... three more rules, for ranges and IPv6
}
}Read the rule aloud: "If the packet did not come from this computer itself, and its
source address is in the ban list, and is not in the allow list, count it and drop
it." Everything else continues as before (policy accept).
Act 5: the ban
The attacker tries five more times:
Plain text
level=INFO msg=decision event=ban address=203.0.113.50 service=ssh reason="5 SSH authentication failures within 10m (latest: failed-password)"Diagram source
sequenceDiagram
participant A as Attacker
participant S as sshd
participant I as ipfence
participant D as Database
participant K as Kernel firewall
A->>S: wrong password (fifth time)
S->>I: journal entry
I->>I: genuine? exempt? count = 5
I->>D: save ban, offense 1, bookmark (one transaction)
I->>K: add 203.0.113.50 to ban4 for 15 minutes
K-->>I: committed
I->>D: mark ban as enforced
A->>K: next packet
K--xA: dropped, no replyNotice the order: database first, firewall second. If the firewall step failed, the ban would be remembered, shown as not enforced with the error, and retried every 15 seconds.
The kernel now holds:
Plain text
set ban4 {
type ipv4_addr
flags timeout
elements = { 203.0.113.50 timeout 14m59s992ms expires 14m57s268ms }
}Status:
Plain text
Enforcement ENABLED
...
kernel-live drop counters (reset when the table is rebuilt and at reboot):
CHAIN SET PACKETS BYTES
input ban4 9 516
...
Active bans (1)
ADDRESS ORIGIN SERVICE OFFENSE EXPIRES IN IN FIREWALL REASON
203.0.113.50 auto ssh 1 14m 57s yes 5 SSH authentication failures within 10m (latest: failed-password)Nine packets have already been dropped. The attacker:
Plain text
1 packets transmitted, 0 received, 100% packet loss
ssh: connect to host 203.0.113.1 port 22: Connection timed outThe ordinary visitor:
Plain text
64 bytes from 203.0.113.1: icmp_seq=1 ttl=64 time=0.028 ms
1 packets transmitted, 1 received, 0% packet lossA dropped packet gets no answer at all. To the attacker your server seems to have vanished.
Act 6: unban, and a second offense
Suppose it was a colleague who forgot a password:
Terminal session
$ sudo ipfence unban 203.0.113.50
unbanned 203.0.113.50 (this does not allowlist it)They can connect again immediately. But ipfence remembers. Five more failures give a six-hour ban:
Plain text
ADDRESS ORIGIN SERVICE OFFENSE EXPIRES IN IN FIREWALL REASON
203.0.113.50 auto ssh 2 5h 59m yes 5 SSH authentication failures within 10m (latest: failed-password)| Offense | Ban length |
|---|---|
| 1st | 15 minutes |
| 2nd | 6 hours |
| 3rd and later | 7 days |
After 30 quiet days the count starts over. unban --reset-history forgets it
immediately. To stop it ever happening to an address, allow it.
Act 7: a web probe
With Nginx enabled, someone asks for secrets. The access log:
Plain text
203.0.113.60 - - [29/Nov/2026:02:43:18 +0000] "GET / HTTP/1.1" 200 615 "-" "curl/8.14.1"
203.0.113.60 - - [29/Nov/2026:02:43:18 +0000] "GET /missing-page HTTP/1.1" 404 146 "-" "curl/8.14.1"
203.0.113.80 - - [29/Nov/2026:02:43:18 +0000] "GET /.env HTTP/1.1" 404 146 "-" "curl/8.14.1"
203.0.113.80 - - [29/Nov/2026:02:43:18 +0000] "GET /.git/config HTTP/1.1" 404 146 "-" "curl/8.14.1"
203.0.113.80 - - [29/Nov/2026:02:43:18 +0000] "GET /.aws/credentials HTTP/1.1" 404 146 "-" "curl/8.14.1"Plain text
203.0.113.80 auto nginx 1 14m 57s yes 3 Nginx exploit probes within 10m (latest: probe:credential-file)The visitor .60 also got a "not found" error, for an ordinary missing page, and
was not penalized. Only the secret-file requests count.
Epilogue: the daemon stops, protection stays
Terminal session
$ sudo systemctl stop ipfence
$ sudo ipfence status
Daemon not running
Enforcement ENABLED
...
$ sudo nft list table inet ipfence
set ban4 {
...
elements = { 198.51.100.200,
203.0.113.80 timeout 14m59s996ms expires 14m56s844ms }
}The bans are in the kernel, which keeps blocking and expires timed ones by itself. Your commands still work with the daemon stopped:
Terminal session
$ sudo ipfence unban 203.0.113.80
unbanned 203.0.113.80 (this does not allowlist it)And to remove every trace from the firewall:
Terminal session
$ sudo ipfence disable --yes
enforcement is off and the ipfence nftables table is gone; ban records are keptNext: Getting started to do this yourself.