sshd: use exponential fail2ban backoff instead of fixed week-long bans#515
Merged
Conversation
The sshd-aggressive jail used maxretry=1 with a flat 7-day bantime, so a single preauth disconnect from a legitimate client — a banner exchange, PQ-kex downgrade, or ControlMaster probe — locked the source IP out for a week. An admin on a dynamic address was banned this way and could only recover via the wg-admin mesh. Enable bantime-increment so bans grow as bantime * 2^(offenses-1) from a 5-minute base to a 1-week cap, and raise sshd-aggressive maxretry to 3. A one-off mistake now costs 5 minutes while persistent abusers still escalate to long bans. overalljails accounts offenses per-IP across both jails rather than per-filter.
The sshd[mode=aggressive] filter treats "Connection closed by authenticating user X <host> [preauth]" as an attack. sshd also logs that line when a normal client reaches the auth phase and then drops -- e.g. an unconfirmed Secretive/Touch-ID prompt or a multiplexed control connection -- so a single such event banned the admin's own address. Add an sshd.local filter overlay whose ignoreregex matches only the "authenticating user <name>" variant, which carries a real username. Anonymous scanners close before offering a username, so they lack this qualifier and are still caught. fail2ban merges NAME.local after NAME.conf, so this overrides the empty stock ignoreregex. Verified with fail2ban-regex against eta's live journal (aggressive mode): 9 legit auth-phase drops now ignored, 5569 attack matches retained.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The sshd-aggressive jail used maxretry=1 with a flat 7-day bantime, so a
single preauth disconnect from a legitimate client — a banner exchange,
PQ-kex downgrade, or ControlMaster probe — locked the source IP out for a
week. An admin on a dynamic address was banned this way and could only
recover via the wg-admin mesh.
Enable bantime-increment so bans grow as bantime * 2^(offenses-1) from a
5-minute base to a 1-week cap, and raise sshd-aggressive maxretry to 3.
A one-off mistake now costs 5 minutes while persistent abusers still
escalate to long bans. overalljails accounts offenses per-IP across both
jails rather than per-filter.
sshd: stop the aggressive fail2ban jail from banning legit sessions
The sshd[mode=aggressive] filter treats "Connection closed by
authenticating user X [preauth]" as an attack. sshd also logs that
line when a normal client reaches the auth phase and then drops -- e.g. an
unconfirmed Secretive/Touch-ID prompt or a multiplexed control connection
-- so a single such event banned the admin's own address.
Add an sshd.local filter overlay whose ignoreregex matches only the
"authenticating user " variant, which carries a real username.
Anonymous scanners close before offering a username, so they lack this
qualifier and are still caught. fail2ban merges NAME.local after NAME.conf,
so this overrides the empty stock ignoreregex.
Verified with fail2ban-regex against eta's live journal (aggressive mode):
9 legit auth-phase drops now ignored, 5569 attack matches retained.