LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 10-26-2010, 10:13 AM   #1
NeilR
LQ Newbie
 
Registered: Aug 2007
Location: Devon, UK
Distribution: Fedora, Arch
Posts: 21

Rep: Reputation: 1
Fail2ban and Hiawatha


I can't get a failregex to match my Hiawatha webserver logs! The log files use "Common Log Format" where the host IP is before the date, but I can't seem to match this with a failregex which wants the date before the IP. Have I missed something obvious?

A sample log entry is:

192.168.0.86 - - [26/Oct/2010:15:13:00 +0100] "GET / HTTP/1.1" 200 3659
 
Old 10-26-2010, 12:23 PM   #2
unSpawn
Moderator
 
Registered: May 2001
Posts: 29,415
Blog Entries: 55

Rep: Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600
Not exactly a security question but what is the regex you tried for the Hiawatha web server log and what does 'fail2ban-regex' return when you try it?
 
Old 10-26-2010, 02:32 PM   #3
NeilR
LQ Newbie
 
Registered: Aug 2007
Location: Devon, UK
Distribution: Fedora, Arch
Posts: 21

Original Poster
Rep: Reputation: 1
Yes, wasn't sure where to ask this! I tried "<HOST>.*GET.*" just to get a match, but get reply "Found a match... but no valid date/time found..." from fail2ban-regex. I also tried various mutations of this regex but get either no match at all, or the found match/no date messages.
 
Old 10-27-2010, 11:54 AM   #4
unSpawn
Moderator
 
Registered: May 2001
Posts: 29,415
Blog Entries: 55

Rep: Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600
What does 'fail2ban-regex "192.168.0.86 - - [26/Oct/2010:15:13:00 +0100] \"GET / HTTP/1.1\" 200 3659" "(?P<host>\S*) [-/\d,.]+ .*GET";' return (post complete output)?
 
Old 10-28-2010, 09:34 AM   #5
NeilR
LQ Newbie
 
Registered: Aug 2007
Location: Devon, UK
Distribution: Fedora, Arch
Posts: 21

Original Poster
Rep: Reputation: 1
Thumbs up

Output follows...

/usr/share/fail2ban/server/filter.py:442: DeprecationWarning: the md5 module is deprecated; use hashlib instead
import md5

Running tests
=============

Use regex line : (?P<host>\S*) [-/\d,.]+ .*GET
Use single line: 192.168.0.86 - - [26/Oct/2010:15:13:00 +0100] "GET...


Results
=======

Failregex
|- Regular expressions:
| [1] (?P<host>\S*) [-/\d,.]+ .*GET
|
`- Number of matches:
[1] 1 match(es)

Ignoreregex
|- Regular expressions:
|
`- Number of matches:

Summary
=======

Addresses found:
[1]
192.168.0.86 (Tue Oct 26 15:13:00 2010)

Date template hits:
0 hit(s): MONTH Day Hour:Minute:Second
0 hit(s): WEEKDAY MONTH Day Hour:Minute:Second Year
0 hit(s): WEEKDAY MONTH Day Hour:Minute:Second
0 hit(s): Year/Month/Day Hour:Minute:Second
0 hit(s): Day/Month/Year Hour:Minute:Second
2 hit(s): Day/MONTH/Year:Hour:Minute:Second
0 hit(s): Month/Day/Year:Hour:Minute:Second
0 hit(s): Year-Month-Day Hour:Minute:Second
0 hit(s): Day-MONTH-Year Hour:Minute:Second[.Millisecond]
0 hit(s): Day-Month-Year Hour:Minute:Second
0 hit(s): TAI64N
0 hit(s): Epoch
0 hit(s): ISO 8601
0 hit(s): Hour:Minute:Second
0 hit(s): <Month/Day/Year@Hour:Minute:Second>

Success, the total number of match is 1

However, look at the above section 'Running tests' which could contain important information.

...Output ends

I have tested this and it works - thanks for the help, though I will have to study this to understand what is happening. Perhaps you could also point in the right direction for the standard Hiawatha log format?
They look like this:

212.183.140.31|Wed 27 Oct 2010 18:02:55 +0100|200|4136||POST / HTTP/1.1|Accept: */*|Accept-Encoding: gzip, deflate|Accep(blah,blah)

Once again, many thanks!

Neil.
 
Old 10-28-2010, 10:29 AM   #6
unSpawn
Moderator
 
Registered: May 2001
Posts: 29,415
Blog Entries: 55

Rep: Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600
Quote:
Originally Posted by NeilR View Post
I have tested this and it works
Cool.


Quote:
Originally Posted by NeilR View Post
point in the right direction for the standard Hiawatha log format?
Not a Linux Security question. Please see the Hiawatha manual for "LogFormat" (hiawatha|common|extended).
 
Old 10-28-2010, 05:30 PM   #7
win32sux
LQ Guru
 
Registered: Jul 2003
Location: Los Angeles
Distribution: Ubuntu
Posts: 9,870

Rep: Reputation: 380Reputation: 380Reputation: 380Reputation: 380
I've moved the thread to Software.
 
Old 10-29-2010, 02:20 AM   #8
NeilR
LQ Newbie
 
Registered: Aug 2007
Location: Devon, UK
Distribution: Fedora, Arch
Posts: 21

Original Poster
Rep: Reputation: 1
I thought I had some understanding of regexes but this has me totally stumped. I cannot work out a regex to match the Hiawatha standard log format, probably because I can't understand why the regex supplied by unSpawn works. Can you help - I'm feeling very stupid here.
 
Old 11-01-2010, 04:30 PM   #9
unSpawn
Moderator
 
Registered: May 2001
Posts: 29,415
Blog Entries: 55

Rep: Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600
I think your best bet is to look into the regexes as they are used in /etc/fail2ban/.*/.* and maybe an "easier" Hiawatha log format. Clearly I'm trying to avoid compiling Hiawatha to find out which log format would be more "default" than your current one but I'd venture it's "LogFormat=extended".

Last edited by unSpawn; 11-01-2010 at 04:31 PM.
 
Old 11-02-2010, 09:40 AM   #10
NeilR
LQ Newbie
 
Registered: Aug 2007
Location: Devon, UK
Distribution: Fedora, Arch
Posts: 21

Original Poster
Rep: Reputation: 1
I think I have figured it out!!! The Hiawatha default log date format is Day DD Mon YYYY:hh:mm:ss (or "%a %e %b %Y %H:%M:%S %z") which it seems fail2ban doesn't support.

Thanks to unSpawn for helping me along the path to understanding!
 
Old 11-07-2010, 09:29 AM   #11
unSpawn
Moderator
 
Registered: May 2001
Posts: 29,415
Blog Entries: 55

Rep: Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600
Quote:
Originally Posted by NeilR View Post
which it seems fail2ban doesn't support.
If you're not going for "LogFormat=extended" then maybe hack fail2ban? Something like this may be a start?
Code:
--- /usr/share/fail2ban/server/datedetector.py  2008-02-27 22:44:55.000000000 +0100
+++ /usr/share/fail2ban/server/datedetect0r.py  2008-02-27 22:45:55.000000000 +0100
@@ -93,6 +93,12 @@
                        template = DateEpoch()
                        template.setName("Epoch")
                        self.__templates.append(template)
+                       # Hiawatha web server default log format
+                       template = DateStrptime()
+                       template.setName("Weekday Day Month Year Hour:Minute:Second TZ")
+                       template.setRegex("\S{3} \s{1,2}\S{3}\d{4} \d{2}:\d{2}:\d{2} \S{5}")
+                       template.setPattern("%a %e %b %Y %H:%M:%S %z")
+                       self.__templates.append(template)
                finally:
                        self.__lock.release()
Not as if I know Python though.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
I need help with fail2ban... trist007 Linux - Newbie 15 12-14-2009 03:22 AM
Hiawatha opinions (webserver)? Jim Bengtson Linux - Security 1 10-17-2009 10:10 PM
Fail2ban, is it working? SuperDude123 Linux - Security 7 02-17-2009 09:09 PM
Need help with fail2ban regex jakev383 Linux - Security 6 12-07-2008 09:35 AM
Fail2ban and Firestarter baldur2630 Linux - Software 2 09-29-2008 05:46 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 08:45 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration