Commit graph

6311 commits

Author SHA1 Message Date
Tobias Knecht
8375f69ccf
Merge 96a2f29dc8 into 6c88de71d2 2026-10-12 11:37:43 +02:00
Sergey G. Brester
6c88de71d2
CI: update python versions (3.15 is released)
Some checks failed
Codespell / Check for spelling errors (push) Has been cancelled
CI / build (3.10) (push) Has been cancelled
CI / build (3.11) (push) Has been cancelled
CI / build (3.12) (push) Has been cancelled
CI / build (3.13) (push) Has been cancelled
CI / build (3.14) (push) Has been cancelled
CI / build (3.15) (push) Has been cancelled
CI / build (3.8) (push) Has been cancelled
CI / build (3.9) (push) Has been cancelled
CI / build (pypy3.11) (push) Has been cancelled
2026-10-11 01:27:08 +02:00
sebres
544aff5dda amend to gh-4196: matches auth-worker message (one line per attempt, <pid><session> in prefix, etc)
Some checks are pending
Codespell / Check for spelling errors (push) Waiting to run
CI / build (3.10) (push) Waiting to run
CI / build (3.11) (push) Waiting to run
CI / build (3.12) (push) Waiting to run
CI / build (3.13) (push) Waiting to run
CI / build (3.14) (push) Waiting to run
CI / build (3.15.0-rc.2) (push) Waiting to run
CI / build (3.8) (push) Waiting to run
CI / build (3.9) (push) Waiting to run
CI / build (pypy3.11) (push) Waiting to run
2026-10-09 20:39:52 +02:00
sebres
789571aa44 filter.d/pam-generic.conf: correctly consider attempt to inject on username for right and both sides;
Some checks are pending
Codespell / Check for spelling errors (push) Waiting to run
CI / build (3.10) (push) Waiting to run
CI / build (3.11) (push) Waiting to run
CI / build (3.12) (push) Waiting to run
CI / build (3.13) (push) Waiting to run
CI / build (3.14) (push) Waiting to run
CI / build (3.15.0-rc.2) (push) Waiting to run
CI / build (3.8) (push) Waiting to run
CI / build (3.9) (push) Waiting to run
CI / build (pypy3.11) (push) Waiting to run
unless proven otherwise, we will prefer injection on the `ruser` field over the `user` field;
normally by invalid user field `user` not logged at all, see for example logging from `pam_syslog(pamh, LOG_NOTICE, "authentication failure; " ...` in pam_unix-module source code:
52b33a56a9/modules/pam_unix/support.c (L822)
2026-10-09 00:06:14 +02:00
sebres
ddd879d226 'filter.d/sshd.conf': properly consider further attempt to inject on username (__on_port_opt and __suff adjusted and don't match on \S+ anymore)
Some checks are pending
Codespell / Check for spelling errors (push) Waiting to run
CI / build (3.10) (push) Waiting to run
CI / build (3.11) (push) Waiting to run
CI / build (3.12) (push) Waiting to run
CI / build (3.13) (push) Waiting to run
CI / build (3.14) (push) Waiting to run
CI / build (3.15.0-rc.2) (push) Waiting to run
CI / build (3.8) (push) Waiting to run
CI / build (3.9) (push) Waiting to run
CI / build (pypy3.11) (push) Waiting to run
2026-10-08 18:48:26 +02:00
sebres
2cc5bed3dc filter.d/common.conf - improved RE for logtype rfc5424 (better compliant to RFC 5424);
Some checks failed
Codespell / Check for spelling errors (push) Has been cancelled
CI / build (3.10) (push) Has been cancelled
CI / build (3.11) (push) Has been cancelled
CI / build (3.12) (push) Has been cancelled
CI / build (3.13) (push) Has been cancelled
CI / build (3.14) (push) Has been cancelled
CI / build (3.15.0-rc.2) (push) Has been cancelled
CI / build (3.8) (push) Has been cancelled
CI / build (3.9) (push) Has been cancelled
CI / build (pypy3.11) (push) Has been cancelled
- fixed prefix-line for malformed RFC 5424, vulnerable against ReDoS (catastrophic backtracking) by non-conform logger or artificial "injection" attempt on STRUCTURED-DATA, unescaped new-line in PARAM-VALUE, etc (GHSA-c2mg-2r7g-c3wp)
2026-09-28 22:20:27 +02:00
Tobias Knecht
96a2f29dc8
DOC: move XARF v4 ChangeLog entries to 1.1.2-dev-1
1.1.1 was released (2026/08/15) while this branch was stale; the
new-feature and deprecation entries were still sitting under that
now-historical section instead of the current dev section.

Also drops a stray trailing blank line left in servertestcase.py from
an earlier test-file truncation.
2026-09-17 13:31:56 +02:00
Tobias Knecht
17328f4643
ENH+TST: fold xarfreport generator into config/action.d/xarf.py
Per review: fail2ban/server/xarfreport.py had exactly one consumer
(this action), and the only other Python action (smtp.py) is fully
self-contained with no bespoke helper module in fail2ban/server/. Move
the generator (build_login_attack and friends) directly into xarf.py
to match that convention; extract it again if a second XARF-based
transport ever needs to share it.

Test classes now load the generator functions off the dynamically
loaded action module (fail2ban/tests/action_d/test_xarf.py already
does this for the action itself) instead of importing a package
module. The module-level logger is now named explicitly
("fail2ban.xarf") since __name__ is just "xarf" for a standalone-
loaded module and would otherwise sit outside the fail2ban.* logger
hierarchy fail2ban's log handlers (and test log capture) attach to.
2026-09-17 13:30:08 +02:00
Tobias Knecht
fe0d8191ee
BF+ENH+TST: fix XARF v4 field-mapping and delivery bugs from review
Addresses review feedback on the xarf action/generator:

- xarf.py: anchor source_port extraction to the banned IP itself,
  rather than taking the last "port N" match in the log line. sshd's
  verbose "Connection from <ip> port NNNNN on 127.0.0.1 port 22" line
  otherwise yielded the local listening port instead of the attacker's.
- xarf.py: replace int(self.port) with a real parser for fail2ban's
  port option (service name, comma list, or range) so destination_port
  is populated for the values jail.conf actually passes (`ssh`,
  `http,https`, `0:65535`), and never emits destination_port: 0, which
  violates the schema's minimum of 1.
- xarf.py: skip reporting entirely when a ban ticket carries no log
  evidence (e.g. a manual `fail2ban-client set <jail> banip <ip>`),
  instead of sending a report claiming attempt_count: 0.
- xarf.py: pass -f <envelope_from> to the mail command by default (new
  mailargs option to override), and resolve the default envelope
  sender via DNSUtils.getHostname() instead of a raw socket.getfqdn().
  Fixes SPF/DMARC alignment and the localhost/PTR edge cases.
- jail.conf: pass sender="%(sender)s" into action_xarf_v4, matching
  action_mw/action_mwl/legacy action_xarf; it was previously dropped
  on the floor.
- xarfreport.py: catch more than ImportError around the optional xarf
  import - an incompatible install (e.g. pydantic mismatch) could
  otherwise crash the whole action instead of falling back to stdlib.
- xarfreport.py: the xarf library ignores the timestamp we pass to
  create_report() and stamps its own, leaving the document internally
  inconsistent with first_seen; now enforced on the returned dict.
- xarfreport.py: distinguish "library unavailable/erroring" (fall back
  to stdlib and still send) from "library validated and rejected the
  report" (XarfValidationError; drop the report rather than send the
  same invalid data unvalidated via the stdlib builder).
- xarf.py: fix malformed emacs modeline.
- ChangeLog: add missing gh-3820 refs.

10 new regression tests in fail2ban/tests/action_d/test_xarf.py, one
per bug above (including a real broken-xarf-install import-guard test
via module reload).
2026-09-17 13:30:08 +02:00
Tobias Knecht
0fbe4f317d
TST: consolidate XARF v4 tests into fail2ban/tests/action_d/test_xarf.py
Move XarfV4ActionTest out of servertestcase.py and the generator tests
out of the standalone xarfreporttestcase.py into a single
action_d/test_xarf.py, matching the existing convention for testing
python actions (see test_smtp.py). Files under action_d/test_*.py are
auto-discovered, so the manual registration in utils.py gatherTests()
is no longer needed.
2026-09-17 13:30:08 +02:00
Tobias Knecht
5c08c2da17
DOC: gitignore local fail2ban-python link
bin/fail2ban-python is a machine-local symlink generated by the test
runner, not source to track.
2026-09-17 13:30:08 +02:00
Tobias Knecht
1e20875588
ENH+TST: best-effort source_port extraction for XARF v4 login_attack; recommend xarf install
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-09-17 13:30:08 +02:00
Tobias Knecht
54165d3cde
ENH: only use xarf library when it exposes the v4 generator API; clarify jail.conf note
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-09-17 13:30:08 +02:00
Tobias Knecht
6b5c685abe
BF: prevent argv flag injection from DNS-resolved abuse contacts in xarf action
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-09-17 13:30:08 +02:00
Tobias Knecht
f52f21e124
ENH+TST: harden xarf v4 action (mail headers, ban guard, From default) + tests
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-09-17 13:30:08 +02:00
Tobias Knecht
20690f66c3
DOC: changelog for XARF v4 reporting action and legacy deprecation
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-09-17 13:30:08 +02:00
Tobias Knecht
78c120203e
DOC: deprecate legacy xarf-login-attack action (x-arf 0.2) 2026-09-17 13:30:08 +02:00
Tobias Knecht
3e04155205
ENH: add action_xarf_v4 shortcut for XARF v4 email reporting
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-09-17 13:30:07 +02:00
Tobias Knecht
3f9cac2728
ENH+TST: wire xarf v4 action ban() end-to-end
Add _iso, _aInfoToData, _sendmail helpers and wire ban() to resolve
abuse contacts, build XARF v4 report + email, set To header, and
send via sendmail. Short-circuits when no contact found.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-09-17 13:30:07 +02:00
Tobias Knecht
5e11dd1fad
ENH+TST: build official XARF v4 multipart/report email
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-09-17 13:30:07 +02:00
Tobias Knecht
0f2d859a28
ENH+TST: resolve abuse contacts via Abusix Contact DB in xarf action
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-09-17 13:30:07 +02:00
Tobias Knecht
c25be3fe0a
ENH+TST: add XARF v4 email action skeleton with identity validation
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-09-17 13:30:07 +02:00
Tobias Knecht
90482944aa
ENH+TST: hybrid XARF v4 generator with optional xarf library
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-09-17 13:30:07 +02:00
Tobias Knecht
dc1aa6a59d
ENH+TST: build XARF v4 login_attack report (stdlib path)
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-09-17 13:30:07 +02:00
Tobias Knecht
9489aeb0a3
ENH+TST: add XARF v4 evidence builder (stdlib)
Create xarfreport module with _build_evidence_stdlib() function to
encode log text as base64, compute SHA256 hash, and produce XARF v4
evidence dictionary. Test validates all fields including payload
decoding, hash format, and size computation.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-09-17 13:30:07 +02:00
sebres
7212404e8f amend to 5cbe4b8b01 (systemd RC-fix): lock by closing of journal too (in afterStop, since _closeJournal used in _reopenJournal in lock, and lock is not reentrant)
Some checks failed
Codespell / Check for spelling errors (push) Has been cancelled
CI / build (3.10) (push) Has been cancelled
CI / build (3.11) (push) Has been cancelled
CI / build (3.12) (push) Has been cancelled
CI / build (3.13) (push) Has been cancelled
CI / build (3.14) (push) Has been cancelled
CI / build (3.15.0-rc.2) (push) Has been cancelled
CI / build (3.8) (push) Has been cancelled
CI / build (3.9) (push) Has been cancelled
CI / build (pypy3.11) (push) Has been cancelled
2026-09-11 22:05:03 +02:00
sebres
f51ad5a5fb CI: update Python version to 3.15.0-rc.2 in workflow 2026-09-11 21:44:15 +02:00
sebres
5cbe4b8b01 prevent possible race condition accessing journal from 2 threads in parallel (sporadic "OSError: [Errno 22] Invalid argument" in test_delJournalMatch by addJournalMatch), protect journal handle with lock 2026-09-11 21:26:11 +02:00
sebres
12e94859b8 remove redundant set exclusion (glob for ../system.journal can never contain ../system*@*.journal) 2026-09-11 20:49:22 +02:00
Sergey G. Brester
86e415a76a
Merge pull request #4230 from ChrisJr404/gitlab-json-mode
Some checks failed
Codespell / Check for spelling errors (push) Has been cancelled
CI / build (3.10) (push) Has been cancelled
CI / build (3.11) (push) Has been cancelled
CI / build (3.12) (push) Has been cancelled
CI / build (3.13) (push) Has been cancelled
CI / build (3.14) (push) Has been cancelled
CI / build (3.15.0-rc.1) (push) Has been cancelled
CI / build (3.8) (push) Has been cancelled
CI / build (3.9) (push) Has been cancelled
CI / build (pypy3.11) (push) Has been cancelled
gitlab: add json mode for application_json.log
2026-08-26 16:06:17 +02:00
Sergey G. Brester
0e2ad0360d
update changelog (mode -> logtype, added PR number) 2026-08-26 16:05:01 +02:00
Chris (ChrisJr404)
7924c55682
gitlab: switch mode parameter to standard logtype (file/json) 2026-08-25 23:47:36 -04:00
Chris (ChrisJr404)
050e0b3460
gitlab: add json mode for application_json.log
Gitlab deprecated application.log in 15.10 in favour of the structured
application_json.log. Add a mode option so the filter can read either
format; text stays the default so existing setups keep working.

Closes #3566
2026-08-24 18:00:21 -04:00
sebres
deffcbcd17 add default banactions for several paths-*.conf depending on default net-filter for distribution;
closes gh-4224, gh-4229
2026-08-22 13:32:00 +02:00
sebres
46d2acd451 ChangeLog 2026-08-22 13:30:47 +02:00
sebres
63c0a46826 add default banactions for several paths-*.conf depending on default net-filter for distribution;
closes gh-4224, gh-4229
2026-08-22 13:26:02 +02:00
Arjen de Korte
c6b20f225c
paths-opensuse.conf: specify default banactions
Since 1.1.1 default banactions need to be specified. Take the opportunity to also synchronize the paths with current Factory settings.
2026-08-21 17:53:28 +02:00
Sergey G. Brester
403df4a91c
Merge pull request #4225 from Deric-W/socket-shutdown
Fix systemd socket activation being broken
2026-08-20 13:46:36 +02:00
Sergey G. Brester
6185bc3ea2
Update ChangeLog entry (added reference to PR) 2026-08-20 13:45:02 +02:00
Eric Wolf
cbdeee8d81
Fix systemd runtime directory containing persistent socket being removed
This resulted in a fail2ban being passed an unreachable socket after being stopped.
2026-08-20 04:03:15 +02:00
Eric Wolf
d574daf22e
Fix sockets passed via socket activation being shut down
Doing so results in systemd encountering errors after stopping fail2ban.
2026-08-20 02:33:06 +02:00
Sergey G. Brester
1e12c5a7c7
Merge pull request #4216 from jarihu/add-cowrie-filter
Add Cowrie honeypot JSON log filter
2026-08-18 15:28:22 +02:00
sebres
5ecbe89c80 try to optimize RE (skipping tags, no full match and right anchor needed), added datepattern, etc 2026-08-18 15:25:19 +02:00
Jari Huttunen
b552116f4f Renamed filter to cowrie 2026-08-18 14:55:18 +02:00
Jari Huttunen
dfb8a58d17 Fixed the CI failure by adding a stock [cowrie] jail entry to config/jail.conf. 2026-08-18 14:54:35 +02:00
Jari Huttunen
9584c78bb6 Fix cowrie_json filter against real Cowrie log output
The previous regex was written against an assumed field order/spacing
that doesn't match what Cowrie actually emits: no space after ":",
and "eventid" is not the first key (order is session, protocol,
src_ip, ..., eventid, ..., message). Rework the failregex to match
real-world json output, and correct the datepattern to wrap only the
timestamp value (not the "timestamp": key) in the capture group, since
fail2ban excises the whole captured group from the line before
failregex is applied - wrapping the key too left a broken ",," gap in
the JSON that never matched.

Verified against real Cowrie honeypot log samples (session.connect,
client.version, client.kex, login.success, log.closed) and the
existing test-suite (101 filter sample-regex tests pass).
2026-08-18 14:51:33 +02:00
Jari Huttunen
763a1c7f0c Fix cowrie honeypot filter per review (PR #4216)
Replace the custom Python Filter/backend hack with a plain regex
filter, per sebres's review: fail2ban filters shouldn't ship a
custom backend-style parser under config/filter.d, and the previous
prefregex/failregex pair was a no-op catch-all that didn't actually
filter anything.

- Drop cowrie_json.py entirely; parse the JSON log line directly
  with a bounded, anchored failregex (no unbounded .* catch-alls)
  using <ADDR> instead of <HOST> since only an IP is expected.
- Add the required sample log test file
  (fail2ban/tests/files/logs/cowrie_json) covering matched,
  non-matching event, and malformed lines.
2026-08-18 14:51:33 +02:00
Jari Huttunen
ae4be51e16 typo fix 2026-08-18 14:51:32 +02:00
Jari Huttunen
4120682a95 Added cowrie honeypot json log filter 2026-08-18 14:51:32 +02:00
Sergey G. Brester
847abb4b2b
Merge pull request #4217 from VXNCXNX/fix/apache-noscript-cgi-bin-dir
filter.d/apache-noscript: match a cgi-bin directory with no script name
2026-08-18 14:39:22 +02:00