LinuxQuestions.org
Review your favorite Linux distribution.
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 07-15-2009, 09:21 AM   #1
Xnake
LQ Newbie
 
Registered: Jul 2005
Location: Spain
Distribution: OpenSuSE 11.1
Posts: 14

Rep: Reputation: 0
fail2ban and qmail


Hi!

I have fail2ban working properly to block FTP attacks and I want to block "SMTP attacks". I mean I want to block IPs sending mails to non-existent adresses in our mail server. In /var/log/qmail/smtpd/current they are logged as :@400000004a5dced82e4669a4 Reject::RCPT::Failed_Rcptto: P:ESMTP S:187.4.68.30:**** H:**** F:fake-email@fakedomain T:non-existant-email@mydomain


I've configured /etc/fail2ban/filter.d/qmail.conf as follows:

# Fail2Ban configuration file
#
# Author: Cyril Jaquier
#
# $Revision: 510 $
#

[Definition]

# Option: failregex
# Notes.: regex to match the password failures messages in the logfile. The
# host must be matched by a group named "host". The tag "<HOST>" can
# be used for standard IP/hostname matching and is only an alias for
# (?:::f{4,6}:)?(?P<host>\S+)
# Values: TEXT
#
#failregex = (?:[\d,.]+[\d,.] rblsmtpd: |421 badiprbl: ip )<HOST>
failregex = Reject::RCPT::Failed_Rcptto: P:ESMTP S:<HOST>

# Option: ignoreregex
# Notes.: regex to ignore. If this regex matches, the line is ignored.
# Values: TEXT
#
ignoreregex =




Also configured /etc/fail2ban/jail.conf to enable qmail:

[qmail-iptables]

enabled = true
filter = qmail
action = iptables[name=QMAIL, port=smtp, protocol=tcp]
sendmail-whois[name=QMAIL, dest=myqmail@mydomain]
logpath = /var/log/qmail/smtpd/current.log
maxretry = 3
bantime = 600




iptable rules are created:

# iptables -L -n --line-numbers
Chain INPUT (policy ACCEPT)
num target prot opt source destination
1 fail2ban-VSFTPD tcp -- 0.0.0.0/0 0.0.0.0/0 tcp dpt:21
2 fail2ban-QMAIL tcp -- 0.0.0.0/0 0.0.0.0/0 tcp dpt:25

Chain FORWARD (policy ACCEPT)
num target prot opt source destination

Chain OUTPUT (policy ACCEPT)
num target prot opt source destination

Chain fail2ban-QMAIL (1 references)
num target prot opt source destination
1 RETURN 0 -- 0.0.0.0/0 0.0.0.0/0

Chain fail2ban-VSFTPD (1 references)
num target prot opt source destination
1 RETURN 0 -- 0.0.0.0/0 0.0.0.0/0





Regular expression seems to be correct:

# fail2ban-regex /var/log/qmail/smtpd/current /etc/fail2ban/filter.d/qmail.conf

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

Use regex file : /etc/fail2ban/filter.d/qmail.conf
Use log file : /var/log/qmail/smtpd/current


Results
=======

Failregex
|- Regular expressions:
| [1] Reject::RCPT::Failed_Rcptto: P:ESMTP S:<HOST>
|
`- Number of matches:
[1] 65 match(es)

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

Summary
=======

Addresses found:
[1]
...
202.157.70.55 (Wed Jul 15 13:57:40 2009)
...

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
0 hit(s): Day/Month/Year:Hour:Minute:Second
0 hit(s): Year-Month-Day Hour:Minute:Second
0 hit(s): Day-Month-Year Hour:Minute:Second[.Millisecond]
5964 hit(s): TAI64N
0 hit(s): Epoch
0 hit(s): ISO 8601

Success, the total number of match is 65

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





But fail2ban doesn't block any IP for qmail.

Anyone can tell what am I doing wrong?

Thanks in advance.

Last edited by Xnake; 07-16-2009 at 06:10 AM.
 
Old 07-15-2009, 01:03 PM   #2
irishbitte
Senior Member
 
Registered: Oct 2007
Location: Brighton, UK
Distribution: Ubuntu Hardy, Ubuntu Jaunty, Eeebuntu, Debian, SME-Server
Posts: 1,213
Blog Entries: 1

Rep: Reputation: 88
You're doing nothing wrong, fail2ban and other 'protection' screens must accept all mail to obey SMTP specs, and then reject, i.e., not queue mail, that meets or does not meet certain conditions. Is there a reason you do not wish to see these?
 
Old 07-16-2009, 03:35 AM   #3
Xnake
LQ Newbie
 
Registered: Jul 2005
Location: Spain
Distribution: OpenSuSE 11.1
Posts: 14

Original Poster
Rep: Reputation: 0
I believed that fail2ban would block any SMTP connection atempt after the attacking IP was spotted in qmail log and no SMTP dialog would happen afterwards.

We block any email with no valid recipient and/or sender and we donīt send any reply, but I want attacking servers not to connect to our mail server so SMTP connection can't occur.
 
Old 07-16-2009, 12:07 PM   #4
irishbitte
Senior Member
 
Registered: Oct 2007
Location: Brighton, UK
Distribution: Ubuntu Hardy, Ubuntu Jaunty, Eeebuntu, Debian, SME-Server
Posts: 1,213
Blog Entries: 1

Rep: Reputation: 88
The point is, if it's an SMTP server, other servers can always connect. What you want is that your server is not relaying messages from users that are not yours, i.e., you want to configure your server so it's not an open relay! Take a look at this for some good info: http://en.wikipedia.org/wiki/Open_mail_relay, and search for securing your mail server.

Frankly, at this stage, if I don't see some activity from people trying to spam through my machine in the logs, I would be worried. It is to be expected. You must be vigilant with your logs!
 
Old 07-22-2009, 04:01 AM   #5
Xnake
LQ Newbie
 
Registered: Jul 2005
Location: Spain
Distribution: OpenSuSE 11.1
Posts: 14

Original Poster
Rep: Reputation: 0
Thank you, irishbitte.

We already had configured our servers not be an open relay, but I wanted those spammers not even connect to our SMTP servers so we don't have to reject the mail.

I would like to release those "bad" connections inmediately so "legal" senders can connect to our SMTP servers.
 
Old 07-22-2009, 03:44 PM   #6
irishbitte
Senior Member
 
Registered: Oct 2007
Location: Brighton, UK
Distribution: Ubuntu Hardy, Ubuntu Jaunty, Eeebuntu, Debian, SME-Server
Posts: 1,213
Blog Entries: 1

Rep: Reputation: 88
Ok, can you post some more info, perhaps a snippet from the logs, an example of a 'bad' connection perhaps? I would like to take a look and compare against my own and some other logs I have on hand.
 
Old 07-23-2009, 03:03 AM   #7
fasuto
LQ Newbie
 
Registered: Jul 2009
Posts: 2

Rep: Reputation: 0
Same happends to me with a different filter in qmail.
The test run fine, catch a lot of ipaddress but once fail2ban is running don't ban anyting. All I can see in the fail2ban logs is "Log rotation detected for /var/log/qmail/qmail-smtpd/current"
 
Old 07-23-2009, 04:00 AM   #8
fasuto
LQ Newbie
 
Registered: Jul 2009
Posts: 2

Rep: Reputation: 0
Xnake:
As a test try this:
Change the logpath to /var/log/test.log

Make a tail -f /var/log/qmail/smtpd/current.log |tai64nlocal >>/var/log/test.log

Reload fail2ban and watch the logs

In my case fail2ban begin to ban ip's so i think is something related to the date format in qmail logs that work different in fail2ban-regex
 
Old 08-19-2009, 05:42 AM   #9
Xnake
LQ Newbie
 
Registered: Jul 2005
Location: Spain
Distribution: OpenSuSE 11.1
Posts: 14

Original Poster
Rep: Reputation: 0
Irishbite, in /var/log/qmail/smtpd/current they are logged as :@400000004a5dced82e4669a4 Reject::RCPT::Failed_Rcptto: P:ESMTP S:187.4.68.30:**** H:**** F:fake-email@fakedomain T:non-existant-email@mydomain

fasuto, thanks for the reply. I think your right, probably fail2ban doesn't ban qmail "attacks" because it doesn't understand qmail log's timestamp.

I'll try to report this issue to fail2ban team so they can fix it. I'll try to find out if there's some way to use "normal" timestamps in qmail logs as well.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
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 Question nomb Debian 0 05-21-2007 07:28 AM
fail2ban and proftpd 1.3 reeseslover531 Linux - Security 4 02-14-2007 07:10 AM
qmail +qmail-qfilter + qmail-scanner-queue+qmail-user-masq.pl problem countcobolt Linux - Networking 0 07-08-2004 11:29 AM

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

All times are GMT -5. The time now is 03:15 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