LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Server
User Name
Password
Linux - Server This forum is for the discussion of Linux Software used in a server related context.

Notices


Reply
  Search this Thread
Old 03-17-2011, 07:47 AM   #1
JeanC
LQ Newbie
 
Registered: Mar 2011
Location: Groningen, Netherlands
Distribution: kubuntu 10.4
Posts: 2

Rep: Reputation: 0
fail2ban does not ban, maybe my regex is wrong?


Edit, this one works for me:
Code:
docroot = /var/www
badadmin = PMA|phpmyadmin|myadmin|mysql|mysqladmin|sqladmin|mypma|admin|xampp|mysqldb|mydb|db|pmadb|zeb|cart
failregex = [[]client <HOST>[]] File does not exist: %(docroot)s/(?:%(badadmin)s)

Hello,

I have a custom made jail for fail2ban to ban scriptkiddies looking for phpmyadmin etc.
Another jail, looking for ftp server inlogs works fine but I can't get this one to work.
Thanks for helping.


failregex = [[]client <HOST>[]] (File does not exist|unable to stat): /\S*(php|pma|PMA|p/m/a|db|sql|admin|zen|cart).*


Corresponding entry in jail.conf:
Code:
[apache-pma]
enabled = true
port    = http,https
filter = apache-pma
logpath = /var/log/apache2/error.log
maxretry = 1
These are in error.log
[Wed Mar 16 23:37:35 2011] [error] [client 210.51.38.77] File does not exist: /var/www/phpmyadmin

Last edited by JeanC; 03-18-2011 at 09:28 AM.
 
Old 03-17-2011, 08:56 AM   #2
Noway2
Senior Member
 
Registered: Jul 2007
Distribution: Gentoo
Posts: 2,125

Rep: Reputation: 781Reputation: 781Reputation: 781Reputation: 781Reputation: 781Reputation: 781Reputation: 781
Welcome to LQ.

Getting regex's to work in fail2ban can sometimes be tricky. I personally haven't had the greatest of luck getting them to work, but I think applying a ban on looking for nonexistent myadmin pages is a laudable action. There is a fail2ban regex test tool that lets you test an expression against the logs and see if it would trigger as a match or not. I have found from working with regex matches in general that they are VERY literal, usually don't do what you expect, and that there are multiple ways to achieve the same result. I have found that a form of trial and error, starting with a very small expression of a literal phrase and expanding on it a bit at a time, works best.

Here is a link to some discussion on the regex test tool that may be of assistance.

Last edited by Noway2; 03-17-2011 at 08:57 AM. Reason: removed redundant wording
 
1 members found this post helpful.
Old 03-17-2011, 10:01 AM   #3
JeanC
LQ Newbie
 
Registered: Mar 2011
Location: Groningen, Netherlands
Distribution: kubuntu 10.4
Posts: 2

Original Poster
Rep: Reputation: 0
Hi Noway2,

I just remembered some minutes ago about the fail2ban-regex tool and how I forgot to include it in my post. I had tried it.
But trying it again, and actually doing exactly what you are suggesting, beginning at a simple expression, I managed to fix it.
It's banning now and I'm sure glad for it, I've seen it going on for hours with these kiddies.

Have a good day.
 
  


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
Perl to find regex and print following 5 lines after regex casperdaghost Linux - Newbie 3 08-29-2010 08:08 PM
[SOLVED] Fail2Ban failed to ban Attack on Asterisk, Why ? MET Linux - Security 10 05-27-2010 04:08 AM
Fail2ban regex help please wvroger Linux - Security 1 05-23-2010 07:30 PM
Fail2ban and Dovecot Regex kevinslair Linux - Software 3 05-31-2009 08:19 PM
Need help with fail2ban regex jakev383 Linux - Security 6 12-07-2008 09:35 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Server

All times are GMT -5. The time now is 06:59 AM.

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