<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Computer Solutions Blog &#187; security</title>
	<atom:link href="http://www.computersolutions.cn/blog/tag/security/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.computersolutions.cn/blog</link>
	<description>Whats happening at Computer Solutions</description>
	<lastBuildDate>Fri, 13 Jan 2012 02:32:34 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>How to setup fail2ban to block vpopmail attacks</title>
		<link>http://www.computersolutions.cn/blog/2009/10/how-to-setup-fail2ban-to-block-vpopmail-attacks/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=how-to-setup-fail2ban-to-block-vpopmail-attacks</link>
		<comments>http://www.computersolutions.cn/blog/2009/10/how-to-setup-fail2ban-to-block-vpopmail-attacks/#comments</comments>
		<pubDate>Thu, 01 Oct 2009 13:04:25 +0000</pubDate>
		<dc:creator>Lawrence Sheed</dc:creator>
				<category><![CDATA[Email]]></category>
		<category><![CDATA[Technical Mumbo Jumbo]]></category>
		<category><![CDATA[fail2ban]]></category>
		<category><![CDATA[how to]]></category>
		<category><![CDATA[security]]></category>
		<category><![CDATA[unix]]></category>
		<category><![CDATA[vpopmail]]></category>

		<guid isPermaLink="false">http://www.computersolutions.cn/blog/?p=269</guid>
		<description><![CDATA[As the Wiki for fail2ban is a little less than explanatory than it could be (and they reversed my edits which made the instructions clearer), here are my own notes on setting up fail2ban to block pop3 attacks. Have been seeing sample dictionary attacks on some servers for a while now from random ip addresses [...]]]></description>
			<content:encoded><![CDATA[<p>As the Wiki for fail2ban is a little less than explanatory than it could be (and they reversed my edits which made the instructions clearer), here are my own notes on setting up fail2ban to block pop3 attacks.</p>
<p>Have been seeing sample dictionary attacks on some servers for a while now from random ip addresses &#8211; eg</p>
<pre class="wp-code-highlight prettyprint">
Sep 28 13:01:03 www vpopmail[20410]: vchkpw-pop3: vpopmail user not found www@:24.153.205.71
Sep 28 13:01:03 www vpopmail[20411]: vchkpw-pop3: vpopmail user not found web@:24.153.205.71
Sep 28 13:01:09 www vpopmail[20417]: vchkpw-pop3: vpopmail user not found web@:24.153.205.71
Sep 28 13:01:11 www vpopmail[20420]: vchkpw-pop3: vpopmail user not found web@:24.153.205.71
</pre>
<p>Annoying, but not realistically going to provide much of a security issue &#8211; most of the user names are the generic ones which aren&#8217;t actually in use on the servers.</p>
<p>As we already use <a href="http://www.fail2ban.org">fail2ban</a> to perform basic service blocks against naughty script kiddie wannabee&#8217;s, why not have it block vpopmail attacks also.</p>
<p>Our mail error logs are located in /var/log/mail.log</p>
<p>As you saw above, the logs show the same common text for each failed login &#8211; </p>
<pre class="wp-code-highlight prettyprint">
vchkpw-pop3: vpopmail user not found web@:24.153.205.71
</pre>
<p>A simple regex to identify that in the logs would look like this (as per the fail2ban wiki)</p>
<pre class="wp-code-highlight prettyprint">
failregex = vchkpw-pop3: vpopmail user not found .*@:&lt;HOST&gt;$
</pre>
<p>First step is to create a filter for fail2ban.</p>
<p>Create /etc/fail2ban/filter.d/vpopmail.conf as below:</p>
<pre class="wp-code-highlight prettyprint">
# Fail2Ban configuration file for vpopmail
#
# Author: Lawrence Sheed
#
# $Revision: 1.0 $
#

[Definition]

# Option: failregex
# Notes.: regex to match the password failures messages in the logfile.
# Values: TEXT
#
failregex = vchkpw-pop3: vpopmail user not found .*@:&lt;HOST&gt;$

# Option:  ignoreregex
# Notes.:  regex to ignore. If this regex matches, the line is ignored.
# Values:  TEXT
#
ignoreregex =
</pre>
<p>Second step is to add our filter to the fail2ban setup</p>
<p>Add this to the bottom of /etc/fail2ban/jail.conf</p>
<pre class="wp-code-highlight prettyprint">
[vpopmail]
enabled = true
port    = pop3
filter  = vpopmail
logpath = /var/log/mail.log
maxretry = 3
</pre>
<p>logpath should be amended to whatever your mail logs for vpopmail appear.<br />
maxretry should be set to a value that you agree with.</p>
<p>Restart fail2ban  with a: /etc/init.d/fail2ban restart<br />
and check that it has added the filter.</p>
<p>tail /var/log/fail2ban.log</p>
<p>You should see a line like this:</p>
<pre class="wp-code-highlight prettyprint">
2009-10-01 12:36:09,590 fail2ban.jail   : INFO   Jail 'vpopmail' started
</pre>
<p>If so, you&#8217;re all set!</p>
<hr />
<p>Some additional tips, as I have found some issues subsequently in Fail2ban on some systems:</p>
<p><font color=red>If you find that fail2ban gives error 200 or 400 on occasion, this is due to a timing issue bug in fail2ban.</font><br />
There are 2 possible solutions:</p>
<h3>Solution 1 &#8211; Edit fail2ban</h3>
<p>Open /usr/bin/fail2ban-client </p>
<p>Look for</p>
<pre class="wp-code-highlight prettyprint">
def __processCmd(self, cmd, showRet = True):
beautifier = Beautifier() for c in cmd:
</pre>
<p>After for c in cmd: add a delay<br />
time.sleep(0.5)</p>
<p>This should look similar to this now &#8211; </p>
<pre class="wp-code-highlight prettyprint">
def __processCmd(self, cmd, showRet = True):
beautifier = Beautifier() for c in cmd:
time.sleep(0.5)
</pre>
<p>Save, and restart fail2ban.  If you still see 200 or 400 issues, increase the delay higher e.g. time.sleep(0.8) </p>
<h3>Solution 2 &#8211; Use a different block method</h3>
<p>Instead of iptables, we can configure fail2ban to use route</p>
<p>Add a config file for this:</p>
<pre class="wp-code-highlight prettyprint">
pico /etc/fail2ban/action.d/route.conf
</pre>
<p>Add this into the file and save it.</p>
<pre class="wp-code-highlight prettyprint">
# Fail2Ban configuration file
[Definition]
actionban = ip route add unreachable &lt;ip&gt;
actionunban = ip route del unreachable &lt;ip&gt;
</pre>
<p>Open /etc/fail2ban/jail.conf</p>
<p>Look for ban action = &#8230; in the [DEFAULT] section, and comment it out with a # at the start of the line<br />
then add<br />
eg</p>
<pre class="wp-code-highlight prettyprint">
#banaction = iptables
banaction = route
</pre>
<p>Save the file.<br />
Restart fail2ban</p>
<p>It will now use route to block bad ip&#8217;s.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.computersolutions.cn/blog/2009/10/how-to-setup-fail2ban-to-block-vpopmail-attacks/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

