Commit Graph

327 Commits (77fda9498c511944687f0fbec01ad68ea29fe5ec)

Author SHA1 Message Date
Steven Hiscocks 9928f1df96 ENH: Allow 255.255.255.0 style mask for ignoreip 2014-02-19 17:51:08 +00:00
Steven Hiscocks 1e9910fcb0 ENH: Added traceback for error log on pyinotify callback when in debug
Thanks to Helmut Grohne for idea on #fail2ban IRC
2014-02-12 22:18:09 +00:00
Steven Hiscocks bda9b7d725 BF: Add handling of exception in pyinotify callback
If error isn't handled, no error messages are printed and the jail
ceases to function.
2014-02-12 18:07:31 +00:00
Steven Hiscocks 4d128db64a BF: asyncserver now ensures all data is sent
Previously was using `send` method, which uses `socket.send`. This does
not guarantee to send all data, and no check was in place to verify
whether all data was sent. Using asynchat built in `push` method,
ensures that all data is sent before closing the connection.
2013-12-28 18:42:03 +00:00
Yaroslav Halchenko 6815190685 BF(2.4): omit date patterns containing %f (.subsec) for Python before 2.5 2013-12-27 02:08:47 -05:00
bes.internal ebd89ec077 New ignorecommand that is added to the ignoreip list from output of an external program
ignorecommand update man and fix protocol help

ENH: run ignore command only after internal list has been examined. Change interface on ignorecommand to take IP as environment variable and return true if it is to be banned

ENH: ignore IP command to take tagged command

DOC: man pages for ingorecommand

TST: add test cases for ignorecommand
2013-12-24 23:55:35 +03:00
Daniel Black b0ea5698b3 BF: prevent process_file being called in pyinotify backend on log rotation. Closes gh-512 2013-12-23 09:18:32 +00:00
Steven Hiscocks d22716ab63 ENH: Add nsd filter and amend DateEpoch to match date format 2013-12-18 22:31:54 +00:00
Daniel Black d402701b9f Merge pull request #452 from grooverdan/early-sighup-ignore
ENH: move signal.signal(signal.SIGHUP, signal.SIG_IGN) before fork in server
2013-12-13 15:33:33 -08:00
Daniel Black a03815facf TST: FileFilter tail tests 2013-12-11 13:07:08 +11:00
Daniel Black f3c4285118 TST: no test coverage on subclass overwritten function _delLogPath 2013-12-11 10:46:52 +11:00
Daniel Black 916649119e ENH: use format string rather than concatination on log message 2013-12-09 23:07:42 +11:00
Steven Hiscocks 7115f64f83 Merge pull request #470 from grooverdan/flush-logs
BF: create flushlogs command to prevent logrotation clobbering logtarget...
2013-12-06 16:30:16 -08:00
Daniel Black e108de3f6d ENH: banning an IP in the ignoreIPList now issues warning to log, but still continues 2013-12-04 22:27:23 +11:00
Daniel Black b5d6310d28 BF: create flushlogs command to prevent logrotation clobbering logtarget. Closes gh-458 2013-12-04 20:51:30 +11:00
Yaroslav Halchenko 3a5983ab0b Merge branch 'bf/syslog-format' of https://github.com/yarikoptic/fail2ban
* 'bf/syslog-format' of https://github.com/yarikoptic/fail2ban:
  Changelog entries for the last changes
  ENH: added optional [PID] matching in recidive.conf
  ENH: reintroducing levelnameinto syslog msgs, time stamp and indentation in non-syslog msgs
  BF/ENH: include [PID] into logging msgs, remove indentation from syslog messages

Conflicts:
	ChangeLog
2013-11-29 19:58:56 -05:00
Daniel Black 99838440c8 DOC: document rational behind 20 character jail name limit 2013-11-28 23:18:34 +11:00
Yaroslav Halchenko a6f085786c ENH: reintroducing levelnameinto syslog msgs, time stamp and indentation in non-syslog msgs
any indentation from syslog msgs wsa removed -- no need
2013-11-24 10:19:50 -05:00
Daniel Black f2c529ca7b ENH: move signal.signal(signal.SIGHUP, signal.SIG_IGN) before fork in server. closes #446 2013-11-23 11:33:41 +11:00
Yaroslav Halchenko d34d8db3d2 BF/ENH: include [PID] into logging msgs, remove indentation from syslog messages
Otherwise leads to incorrect parsing of the log messages by syslog(-ng). See
http://bugs.debian.org/730202

I also removed %(levelname)-6s from syslog messages completely since they are
passed to the syslog and it is up to the configuration/admin to decide include
levels into the messages or not (I have checked that at least debug level indeed
goes to /var/log/debug)
2013-11-22 15:57:03 -05:00
Yaroslav Halchenko d4f6ca4f85 ENH: adding custom date format for proftpd when logging in its own log file (default on Debian) -- includes milliseconds
Should resolve Debian #648276
2013-11-16 22:15:58 -05:00
Daniel Black caf284d518 DOC: ChangeLog deconflict 2013-10-02 09:11:15 +10:00
Steven Hiscocks a8f2448349 ENH: Allow SE Linux epoch date detection 2013-09-30 20:58:24 +01:00
Daniel Black 6224d761ab BF: simplify 2013-09-29 15:49:45 +10:00
Daniel Black 4d1c060e21 ENH: dont execute empty commands 2013-09-29 13:14:52 +10:00
Daniel Black 4b5ecbccd1 ENH: debuggex URLs with fail2ban-regex 2013-09-22 13:20:17 +10:00
Yaroslav Halchenko f1adf75b59 ENH: basic testing for iso8601 code which had no explicit tests + spit out ValueError for incorrect type of input and ParseError otherwise 2013-09-12 23:12:18 -04:00
Daniel Black b589533d69 Merge branch 'master' into kwirk-merge
Conflicts:
	ChangeLog
	testcases/files/logs/dropbear
2013-08-25 21:21:14 +10:00
Daniel Black ced271b908 ENH: date for apache-2.4 - adds milliseconds 2013-08-25 21:11:47 +10:00
Yaroslav Halchenko c84a2e595a ENH(BF): put 'standard' template after more detailed ones with day of week and year
otherwise years present in the freshly contributed by Dan apache regexes do not match
although should have.  I had also to adjust failing now vsftpd test
2013-08-25 17:52:12 +10:00
Yaroslav Halchenko c0456fd835 BF: Fixing a name for MySQL date pattern which misplaced Year (should not effect functionality) Closes #312 2013-08-08 09:47:47 -04:00
Steven Hiscocks 1e270078b4 TST: Warn if date templates overlap in default detectors 2013-07-27 20:21:05 +01:00
Yaroslav Halchenko 3b52eca608 ENH+TST: Ticket -- drop unused/bogus get|setFile + enh __str__ + basic testing 2013-07-22 12:09:33 -04:00
Steven Hiscocks bf05f2ac95 Merge branch 'filter-failregex-return'
Conflicts:
	server/filter.py
2013-07-16 21:17:18 +01:00
Yaroslav Halchenko 0a02cfe9e8 ENH: <HOST> must end with alphanumeric \w (not a dot or a dash etc)
Otherwise <HOST> regexp might swallow period in the sentence right after the address.
I have decided to enforce alphanumeric instead of switching to non-greedy +? ... because
I think it is closer to what we actually want here
2013-07-16 15:03:06 -04:00
Yaroslav Halchenko 148cbd8d2a ENH: heavier debugging -- log split date/log line even for no match. Log matching regex upon match 2013-07-16 14:16:23 -04:00
Steven Hiscocks 1a2b6442a0 ENH+BF+TST: Filter now returns reference to failregex and ignoreregex
This avoids duplication of code across fail2ban-regex and samples test
cases. This also now more neatly resolves the issue of double counting
date templates matches in fail2ban-regex.
In addition, the samples test cases now also print a warning message
that not all regexs have samples for them, with future plan to change
this to an assertion.
2013-07-15 22:22:13 +01:00
Steven Hiscocks 40f67c64b8 TST: Test sample logs' entries are matched by filter regexs 2013-07-13 23:03:01 +01:00
Yaroslav Halchenko e282d6b1c7 ENH: Remove unused any longer _ctime helper 2013-07-03 00:09:39 -04:00
Yaroslav Halchenko 5df6796e69 ENH: DNS resolution -- catch parent exception
IMHO there is no good reason to capture only gaierror.

on my network it was consistent to error out with

======================================================================
ERROR: testIgnoreIPNOK (testcases.filtertestcase.IgnoreIP)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/yoh/deb/gits/fail2ban/testcases/filtertestcase.py", line 166, in testIgnoreIPNOK
    self.assertFalse(self.filter.inIgnoreIPList(ip))
  File "/home/yoh/deb/gits/fail2ban/server/filter.py", line 277, in inIgnoreIPList
    ips = DNSUtils.dnsToIp(i)
  File "/home/yoh/deb/gits/fail2ban/server/filter.py", line 625, in dnsToIp
    return socket.gethostbyname_ex(dns)[2]
error: [Errno 11] Resource temporarily unavailable

with this commit tests would pass normally as they should
2013-07-02 23:51:09 -04:00
Yaroslav Halchenko 8d25e83f5d BF: race condition -- file should not be read unless it is not empty
Previous code would store md5sum of an empty line as the one
identifying the monitored file.  That file then was read and possibly
failures were found.  Upon next "container.open()", md5 digest of now
present first line was compared against previous digest of an empty
line, which was different, thus file was assumed to be rotated and all
the log lines were read once again.

The History
-----------
In rare cases various tests failed somewhat consistently.  Below you
can find one case in test_move_file where such failure really made no
sense -- we should have not had 4 failures by that point.

Fail2ban 0.8.10.dev test suite. Python 2.4.6 (#2, Sep 25 2009, 22:22:06) [GCC 4.3.4]. Please wait...
I: Skipping gamin backend testing. Got exception 'No module named gamin'
I: Skipping pyinotify backend testing. Got exception 'No module named pyinotify'
D: fn=/home/yoh/test/monitorfailures_FilterPoll9nUKoCfail2ban-0 hashes=d41d8cd98f00b204e9800998ecf8427e/d41d8cd98f00b204e9800998ecf8427e inos=5398862/5398862 pos=0 rotate=False
D: Adding a ticket for ('193.168.0.128', 1124013599.0, ['Aug 14 11:59:59 [sshd] error: PAM: Authentication failure for kevin from 193.168.0.128\n'])
D: Adding a ticket for ('193.168.0.128', 1124013599.0, ['Aug 14 11:59:59 [sshd] error: PAM: Authentication failure for kevin from 193.168.0.128\n'])
D: Closed <closed file '/home/yoh/test/monitorfailures_FilterPoll9nUKoCfail2ban-0', mode 'r' at 0x7f472b2efdc8> with pos 1231
D: fn=/home/yoh/test/monitorfailures_FilterPoll9nUKoCfail2ban-0 hashes=d41d8cd98f00b204e9800998ecf8427e/aeb4e73e6922a746d027eb365ece2149 inos=5398862/5398862 pos=1231 rotate=True
D: Adding a ticket for ('193.168.0.128', 1124013599.0, ['Aug 14 11:59:59 [sshd] error: PAM: Authentication failure for kevin from 193.168.0.128\n'])
D: Adding a ticket for ('193.168.0.128', 1124013599.0, ['Aug 14 11:59:59 [sshd] error: PAM: Authentication failure for kevin from 193.168.0.128\n'])
D: Closed <closed file '/home/yoh/test/monitorfailures_FilterPoll9nUKoCfail2ban-0', mode 'r' at 0x7f472b2ef558> with pos 1231
F
======================================================================
FAIL: test_move_file (testcases.filtertestcase.MonitorFailures<FilterPoll>(/home/yoh/test/monitorfailures_FilterPoll9nUKoCfail2ban))
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/yoh/deb/gits/fail2ban/testcases/filtertestcase.py", line 451, in test_move_file
    "Queue must be empty but it is not: %s."
AssertionError: Queue must be empty but it is not: server.ticket.FailTicket: ip=193.168.0.128 time=1124013599.0 #attempts=4.

----------------------------------------------------------------------

N.B.1 I preserved here and in the code corresponding additional debug
print statements, which are commented out by default. sensible md5
digest was generated by using hexdigest() instead of current a bit
faster digest().  Running tests with all the debug output simply
breaks the race loose and failure doesn't trigger.

N.B.2 d41d8cd98f00b204e9800998ecf8427e is an md5sum of an empty
string, and aeb4e73e6922a746d027eb365ece2149 of the first line in that
file.
2013-07-02 23:37:23 -04:00
Yaroslav Halchenko f340e5c0f5 ENH(+possibly BF): for FilterPoll rely not only on mtime but also ino and size to assess if file was modified
mtime alone is a poor measure here as many of our tests shown -- on older Pythons and some file systems
mtime might be reported only with precision up to a second.  If file gets rotated fast, or there are new
modifications within the same second, fail2ban might miss them with Polling backend if judging only by
mtime.  With this modification we will track also inode and size which are all indicative of a file
change.
2013-07-02 20:43:51 -04:00
Yaroslav Halchenko 2ffc143597 ENH: more of heavydebug'ing for FilterPoll 2013-07-02 19:49:41 -04:00
Yaroslav Halchenko 591590860a BF: setSleepTime -- would barf since value is not str (wasn't used/tested) 2013-07-02 17:11:24 -04:00
Yaroslav Halchenko 97f9cfc0b0 ENH: 'heavydebug' level == 5 for even more debugging in tricky cases
I mocked logging library directly -- seems to be Ok.
2013-06-13 23:19:28 -04:00
Yaroslav Halchenko 21474884e0 ENH: now we know that logging handlers closing was still buggy in 2.6.2 2013-05-12 22:55:02 -04:00
Yaroslav Halchenko 571ff33fde ENH: issue a warning if jail name is longer than 19 symbols (Close #222) 2013-05-12 22:19:50 -04:00
Yaroslav Halchenko 14f92d9144 Merge pull request #225 from yarikoptic/master
Additional check that pyinotify is functional on this platform to enable it
2013-05-12 17:24:17 -07:00
Steven Hiscocks 8af3ffb332 BF: Fix for filterpoll incorrectly checking for jailless state 2013-05-10 16:54:53 +01:00
Yaroslav Halchenko 8161038987 ENH: strengthen detection of working pyinotify
Even though import might work -- pyinotify might be dysfunctional.
Check by creating/deleting a dummy WatchManager upon import
2013-05-10 11:40:12 -04:00