<?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>No pain no gain &#187; Security</title>
	<atom:link href="http://www.dikant.de/category/security/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.dikant.de</link>
	<description>Personal blog of Peter Dikant</description>
	<lastBuildDate>Sun, 23 May 2010 20:57:46 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Securing SSH server with fail2ban</title>
		<link>http://www.dikant.de/2009/06/19/securing-ssh-server-with-fail2ban/</link>
		<comments>http://www.dikant.de/2009/06/19/securing-ssh-server-with-fail2ban/#comments</comments>
		<pubDate>Fri, 19 Jun 2009 17:06:02 +0000</pubDate>
		<dc:creator>Peter</dc:creator>
				<category><![CDATA[Security]]></category>

		<guid isPermaLink="false">http://www.dikant.de/?p=76</guid>
		<description><![CDATA[When you are running your SSH server on the standard port 22, you likely see brute force login attempts multiple times a day. The SSH server does not limit unsuccessfull login attempts by itself. So there are multiple ways to &#8230; <a href="http://www.dikant.de/2009/06/19/securing-ssh-server-with-fail2ban/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>When you are running your SSH server on the standard port 22, you likely see brute force login attempts multiple times a day. The SSH server does not limit unsuccessfull login attempts by itself. So there are multiple ways to deal with this problem.</p>
<p>One option is to move the SSH daemon to a non-standard port. But this means that you might get problems connecting yourself to the server if you are working from a restricted network. So another solution would be to use certificates for login. But then you need to make sure that you carry the certificates with you when you want to login to your server.</p>
<p>Now a good solution is to limit access to the SSH server. One way would be to use the so called port-knocking approach. Here the access to the SSH port is blocked until you use some kind of secret knock-sequence. Then the port will be unblocked for your IP for a certain time. This is very effective but has the downside that you always need to use this knock mechanism before connecting to your server.</p>
<p><span id="more-76"></span></p>
<p>What I prefer is a mechanism which works the other way around. The access to the SSH port is open until there are a number of failed login attempts detected. If this is the case, the IP address these login attempts came from will be blocked for a couple of hours. This approach is less secure then the port knocking approach but is a lot more convenient for me. As long is I don&#8217;t mess up multiple times with the login, I do not even notice any security restrictions. Brute force attacks on the other hand are blocked right away.</p>
<p>The most common tool for this task is the excellent <a href="http://www.fail2ban.org">fail2ban</a>. On a Debian system it can be installed via <code>aptitude</code>:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">aptitude</span> <span style="color: #c20cb9; font-weight: bold;">install</span> fail2ban</pre></div></div>

<p>The default configuration is already useful. It will secure the SSH daemon with a blocking time of 10 minutes after 6 failed login attempts. The configuration files can be found in the directory <code>/etc/fail2ban</code>.</p>
<p>You can change the blocking time in the file <code>/etc/fail2ban/jail.conf</code>:</p>

<div class="wp_syntax"><div class="code"><pre class="config" style="font-family:monospace;">[DEFAULT]
bantime  = 7200
maxretry = 4</pre></div></div>

<p>This will change the default settings which apply if not specified otherwise in the application settings. The setting <code>bantime</code> is specified in seconds and defines how long the blocked IP will not be able to connect to the blocked service. <code>maxretry</code> is the number of failed login attempts.</p>
<p>Lets take a look at the ssh setting:</p>

<div class="wp_syntax"><div class="code"><pre class="config" style="font-family:monospace;">[ssh]
enabled = true
port    = ssh
filter  = sshd
logpath  = /var/log/auth.log
maxretry = 3</pre></div></div>

<p>You can enable or disable the monitoring of specific services (ports). The ssh monitoring uses the <code>auth.log</code> file to detect failed login attempts.</p>
<p>To activate changed configuration settings, just reload the service:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>init.d<span style="color: #000000; font-weight: bold;">/</span>fail2ban force-reload</pre></div></div>

<p>So what happens when an IP is blocked? Once the login attempt limit has been reached, the IP address will be blocked via iptables. Here is the output of iptables on my system:</p>

<div class="wp_syntax"><div class="code"><pre class="config" style="font-family:monospace;">Chain INPUT (policy ACCEPT)
target     prot opt source               destination
fail2ban-ssh  tcp  --  0.0.0.0/0            0.0.0.0/0           multiport dports 22
&nbsp;
Chain FORWARD (policy ACCEPT)
target     prot opt source               destination
&nbsp;
Chain OUTPUT (policy ACCEPT)
target     prot opt source               destination
&nbsp;
Chain fail2ban-ssh (1 references)
target     prot opt source               destination
DROP       all  --  123.456.789.012        0.0.0.0/0
RETURN     all  --  0.0.0.0/0            0.0.0.0/0</pre></div></div>

<p>I have replaced the blocked IP address with some default numbers, but you can see that all traffic from this IP address to the port 22 will be blocked. This iptables rule will be automatically removed after the specified blockout time.</p>
<p>fail2ban is an effective tool to lock out brute force login attempts. It is really easy to setup and can be used to monitor multiple services besides SSH.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.dikant.de/2009/06/19/securing-ssh-server-with-fail2ban/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
	</channel>
</rss>
