<?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>Gorges Blog &#187; ssh</title>
	<atom:link href="http://blog.GORGES.us/tag/ssh/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.GORGES.us</link>
	<description>Web Sites that Grow Your Business - our blog</description>
	<lastBuildDate>Mon, 06 Feb 2012 14:23:43 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>Distributed Dictionary Attack Solutions</title>
		<link>http://blog.GORGES.us/2010/06/distributed-dictionary-attack-solutions/</link>
		<comments>http://blog.GORGES.us/2010/06/distributed-dictionary-attack-solutions/#comments</comments>
		<pubDate>Sat, 26 Jun 2010 11:58:10 +0000</pubDate>
		<dc:creator>Matt Clark</dc:creator>
				<category><![CDATA[Security]]></category>
		<category><![CDATA[System Administration]]></category>
		<category><![CDATA[dictionary attack]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[security]]></category>
		<category><![CDATA[ssh]]></category>
		<category><![CDATA[zombie]]></category>

		<guid isPermaLink="false">http://blog.GORGES.us/?p=283</guid>
		<description><![CDATA[Learn some ideas on how to thwart distributed dictionary attacks on your servers.]]></description>
			<content:encoded><![CDATA[<p>We have had the misfortune of having attempted distributed dictionary attacks on our Linux servers.  A dictionary attack uses a long list of common usernames and passwords trying to find a way to gain a foothold and eventually root access of a password-protected server.</p>
<p>Our servers use utilities such as <a href="http://www.fail2ban.org/">fail2ban</a> or <a href="http://denyhosts.sourceforge.net/">denyhosts</a> that look for repeated failed login attempts, and once found they direct the firewall service to ban the originating IP addresses.  However this technique fails when the attack is distributed among thousands of compromised &#8220;zombie&#8221; computers that are doing the bidding of a malicious hacker.</p>
<p>Our log files correctly diagnosed each attempt from an individual IP address, but a new attempt was immediately started from a different IP address.  We were clearly looking at an attack coordinated from a single unknown source.</p>
<p>There are several ways to reduce or thwart these attacks, including:</p>
<ul>
<li>never allow remote root logins (but attacks still occur on  non-root-user names)</li>
<li>have a chroot jail shell in case an attack on a non-root account succeeds</li>
<li>changing SSH service to use a non-obvious port (such as port 5022 instead of 22)</li>
<li>deactivate password authentication and rely exclusively on authentication keys</li>
<li>restrict allowed IP address by country of origin</li>
<li>only allow certain IP addresses or ranges of addresses to have access</li>
</ul>
<p>We chose to implement more than one of these solutions, and I wanted to share some techniques we used for our implementation.</p>
<p>For the last rule that only allows certain IP addresses, I wanted to start with a list of valid IP addresses used in the last month.  The following script extracts these IP numbers from our SSH log file, sorts them alphabetically, and then removes duplicates.  Note that this server uses Fedora &#8211; you may need to tweak it for other linux distributions.</p>
<pre class="brush: java; title: ; notranslate">
root# fgrep &quot;Accepted&quot; /var/log/secure* | awk '{print $11}' | sort | uniq
166.77.6.4
205.232.34.1
67.255.5.155
...
</pre>
<p>The IP addresses from the above script should be added to the file <strong>/etc/hosts.allow</strong> in the following format:</p>
<pre class="brush: plain; title: ; notranslate">
# hosts.allow   This file contains access rules which are used to
#               allow or deny connections to network services that
#               either use the tcp_wrappers library or that have been
#               started through a tcp_wrappers-enabled xinetd.
#
#               See 'man 5 hosts_options' and 'man 5 hosts_access'
#               for information on rule syntax.
#               See 'man tcpd' for information on tcp_wrappers

# allow local addresses
all: 127.0.0.1
all: 192.168.1.*

# valid IP addresses gathered June 2010
all: 166.77.6.4
all: 205.232.34.1
all: 67.255.5.155
...
</pre>
<p>Now disallow all other IP addresses for SSH by editing the file <strong>/etc/hosts.deny</strong>:</p>
<pre class="brush: plain; title: ; notranslate">
# hosts.deny    This file contains access rules which are used to
#               deny connections to network services that either use
#               the tcp_wrappers library or that have been
#               started through a tcp_wrappers-enabled xinetd.
#
#               The rules in this file can also be set up in
#               /etc/hosts.allow with a 'deny' option instead.
#
#               See 'man 5 hosts_options' and 'man 5 hosts_access'
#               for information on rule syntax.
#               See 'man tcpd' for information on tcp_wrappers
#
# The portmap line is redundant, but it is left to remind you that
# the new secure portmap uses hosts.deny and hosts.allow.  In particular
# you should know that NFS uses portmap!

# deny SSH service except for IP numbers in /etc/hosts.allow file
sshd: all
</pre>
<p>Restart your SSH service, and your server should now be a bit more secure against distributed dictionary attacks:</p>
<pre class="brush: plain; title: ; notranslate">
root# service sshd restart
</pre>
<p>An Internet search using keywords from the other mentioned solutions above will teach you how to change SSH port, disallow password authentication, etc.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.GORGES.us/2010/06/distributed-dictionary-attack-solutions/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

