<?xml version="1.0" encoding="utf-8" ?>

<rss version="2.0" 
   xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
   xmlns:admin="http://webns.net/mvcb/"
   xmlns:dc="http://purl.org/dc/elements/1.1/"
   xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
   xmlns:wfw="http://wellformedweb.org/CommentAPI/"
   xmlns:content="http://purl.org/rss/1.0/modules/content/"
   xmlns:creativeCommons="http://backend.userland.com/creativeCommonsRssModule">
<channel>
    <title>freebsd.munk.me.uk - FTP</title>
    <link>http://freebsd.munk.me.uk/</link>
    <description>FreeBSD System Administration</description>
    <dc:language>en</dc:language>
    <generator>Serendipity 1.5.2 - http://www.s9y.org/</generator>
    
    <image>
        <url>http://freebsd.munk.me.uk/templates/default/img/s9y_banner_small.png</url>
        <title>RSS: freebsd.munk.me.uk - FTP - FreeBSD System Administration</title>
        <link>http://freebsd.munk.me.uk/</link>
        <width>100</width>
        <height>21</height>
    </image>

<item>
    <title>Block Brute Force Attacks Against sshd and proftpd Using blockhosts</title>
    <link>http://freebsd.munk.me.uk/archives/209-Block-Brute-Force-Attacks-Against-sshd-and-proftpd-Using-blockhosts.html</link>
            <category>FTP</category>
            <category>Security</category>
            <category>SSH</category>
    
    <comments>http://freebsd.munk.me.uk/archives/209-Block-Brute-Force-Attacks-Against-sshd-and-proftpd-Using-blockhosts.html#comments</comments>
    <wfw:comment>http://freebsd.munk.me.uk/wfwcomment.php?cid=209</wfw:comment>

    <slash:comments>4</slash:comments>
    <wfw:commentRss>http://freebsd.munk.me.uk/rss.php?version=2.0&amp;type=comments&amp;cid=209</wfw:commentRss>
    

    <author>nospam@example.com (munk)</author>
    <content:encoded>
    For a long time now I&#039;ve had a lot of problems with brute force attacks against sshd and proftpd - attacks where a host will attempt to login with a dictionary of common usernames and passwords, trying each one until they find a combination that works.  Apart from being a security issue, this uses up a lot of bandwidth so it&#039;s worth taking some measures to block these kind of attacks.&lt;br /&gt;
&lt;br /&gt;
Both sshd and ftpd services have their own individual means for blocking individual connections, but unfortunately neither have an inbuilt method for detecting brute force attacks - counting how many failed login attempts are made from each individual IP address and then blocking that IP address if the number of failed login attempts is more than a certain number.  This is where a 3rd party utility is required.&lt;br /&gt;
&lt;br /&gt;
There are a few utilities that can mitigate brute force attacks on services.  For a while now I&#039;ve used &lt;a href=&quot;http://denyhosts.sourceforge.net/&quot;  title=&quot;DenyHosts&quot;&gt;DenyHosts&lt;/a&gt; successfully to block sshd brute force attacks.  DenyHosts works by constantly monitoring sshd logfiles and keeping track of how many failed logins have occured per IP address over time.  If the number of failed logins reaches a certain threshold, DenyHosts adds an entry in /etc/hosts.allow that effectively blocks the IP address, stopping that host from connecting to the sshd service any more.&lt;br /&gt;
&lt;br /&gt;
DenyHosts is great, but unfortunately it&#039;s aimed only at blocking sshd brute force attacks and I need to protect the ftpd service as well as just sshd - and in future maybe adapt to block other services.  With this in mind I decided to move to using a very similar script called &lt;a href=&quot;http://www.aczoom.com/tools/blockhosts/&quot;  title=&quot;BlockHosts&quot;&gt;BlockHosts&lt;/a&gt; (the documentation for BlockHosts actually mentions that it was inspired by DenyHosts).  BlockHosts can scan a list of service logfiles in one go instead of just a single logfile as with DenyHosts, so is ideal for monitoring a number of different services for brute force attacks.&lt;br /&gt;
&lt;br /&gt;
The following describes how to install and configure BlockHosts on FreeBSD so it&#039;s executed every time the sshd or proftpd services are accessed using TCP_WRAPPERS - ie modifying /etc/hosts.allow so the blockhosts script is run each time sshd or proftpd are accessed.  The BlockHosts script will then check if this current connection attempt is part of a brute force attack and if so, add a blocking rule to /etc/hosts.allow to deny further access.&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-weight:bold&quot;&gt;Installation of BlockHosts&lt;/span&gt;&lt;br /&gt;
&lt;ol&gt;&lt;li&gt;&lt;a href=&quot;http://www.aczoom.com/cms/blockhosts/download&quot;  title=&quot;BlockHosts download page&quot;&gt;Download blockhosts from the download page&lt;/a&gt;, extract the distribution (note please check the download link for the latest version, the version below was latest at time of writing):&lt;br /&gt;
&lt;div class=&quot;bb-code-title&quot;&gt;CODE:&lt;/div&gt;&lt;div class=&quot;bb-code&quot;&gt;root@users&amp;#160;/home/munk/bin/python/blockhosts#&amp;#160;wget&amp;#160;http&amp;#58;//www.aczoom.com/tools/blockhosts/BlockHosts-1.0.5.tar.gz&lt;br /&gt;
root@users&amp;#160;/home/munk/bin/python/blockhosts#&amp;#160;tar&amp;#160;zxvf&amp;#160;BlockHosts-1.0.5.tar.gz&lt;br /&gt;
BlockHosts-1.0.5/&lt;br /&gt;
BlockHosts-1.0.5/Makefile&lt;br /&gt;
...&lt;/div&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;li&gt;Change to BlockHosts directory:&lt;br /&gt;
&lt;div class=&quot;bb-code-title&quot;&gt;CODE:&lt;/div&gt;&lt;div class=&quot;bb-code&quot;&gt;root@users&amp;#160;/home/munk/bin/python/blockhosts#&amp;#160;cd&amp;#160;BlockHosts-1.0.5&lt;/div&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;li&gt;Edit and save blockhosts.py to read:&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;bb-code-title&quot;&gt;CODE:&lt;/div&gt;&lt;div class=&quot;bb-code&quot;&gt;CONFIG_FILE&amp;#160;=&amp;#160;&quot;/usr/local/etc/blockhosts.cfg&quot;&lt;br /&gt;
...&lt;br /&gt;
&amp;#160;&amp;#160;&amp;#160;&amp;#160;&quot;LOGFILES&quot;&amp;#58;&amp;#160;&amp;#40;&amp;#160;&quot;/var/log/auth.log&quot;,&amp;#160;&amp;#41;,&lt;/div&gt;&lt;br /&gt;
&lt;span style=&quot;font-weight:bold&quot;&gt;Note:&lt;/span&gt; may seem a bit odd editing the blockhosts.py script before it&#039;s installed - the reason for this is that the installation locations used by setup.py below are taken from blockhosts.py, so by modifying blockhosts.py like this we get the config file installed into /usr/local/etc/ (FreeBSD default for 3rd party software) instead of into /etc (default for linux 3rd party software).&lt;br /&gt;
&lt;br /&gt;
&lt;li&gt;Install blockhosts:&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;bb-code-title&quot;&gt;CODE:&lt;/div&gt;&lt;div class=&quot;bb-code&quot;&gt;root@users&amp;#160;/home/munk/bin/python/blockhosts/BlockHosts-1.0.5#&amp;#160;python&amp;#160;setup.py&amp;#160;-v&amp;#160;install&lt;br /&gt;
running&amp;#160;install&lt;br /&gt;
running&amp;#160;build&lt;br /&gt;
running&amp;#160;build_scripts&lt;br /&gt;
creating&amp;#160;build&lt;br /&gt;
creating&amp;#160;build/scripts-2.4&lt;br /&gt;
copying&amp;#160;and&amp;#160;adjusting&amp;#160;blockhosts.py&amp;#160;-&amp;#62;&amp;#160;build/scripts-2.4&lt;br /&gt;
changing&amp;#160;mode&amp;#160;of&amp;#160;build/scripts-2.4/blockhosts.py&amp;#160;from&amp;#160;644&amp;#160;to&amp;#160;755&lt;br /&gt;
running&amp;#160;install_scripts&lt;br /&gt;
copying&amp;#160;build/scripts-2.4/blockhosts.py&amp;#160;-&amp;#62;&amp;#160;/usr/local/bin&lt;br /&gt;
changing&amp;#160;mode&amp;#160;of&amp;#160;/usr/local/bin/blockhosts.py&amp;#160;to&amp;#160;755&lt;br /&gt;
running&amp;#160;install_data&lt;br /&gt;
copying&amp;#160;blockhosts.cfg&amp;#160;-&amp;#62;&amp;#160;/usr/local/etc&lt;/div&gt;&lt;br /&gt;
&lt;br /&gt;
This installs the blockhosts.py script into /usr/local/bin and the config file blockhosts.cfg into /usr/local/etc.  Make sure to run &#039;rehash&#039; to reread the binary paths again so blockhosts.py will run from anywhere:&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;bb-code-title&quot;&gt;CODE:&lt;/div&gt;&lt;div class=&quot;bb-code&quot;&gt;root@users&amp;#160;/home/munk/bin/python/blockhosts/BlockHosts-1.0.5#&amp;#160;rehash&lt;/div&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;li&gt;Edit and save the /usr/local/etc/blockhosts.cfg file so it reads:&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;bb-code-title&quot;&gt;CODE:&lt;/div&gt;&lt;div class=&quot;bb-code&quot;&gt;LOGFILES&amp;#160;=&amp;#160;&amp;#91;&amp;#160;&quot;/var/log/auth.log&quot;,&amp;#160;&quot;/var/log/ftp.log&quot;&amp;#160;&amp;#93;&lt;/div&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-weight:bold&quot;&gt;Important:&lt;/span&gt;&lt;br /&gt;
Add the logfiles you want blockhosts to monitor for brute force attacks here.  /var/log/auth.log is standard for sshd, /var/log/ftp.log is maybe not standard for all ftpd, this is just what I have setup here.&lt;br /&gt;
&lt;br /&gt;
At this point it&#039;s best to read through the documentation for blockhosts completely - the README, INSTALL and the blockhosts.py script itself.  The following section is pretty much copy/pasted from what&#039;s mentioned in there.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;li&gt;Edit and save /etc/hosts.allow to include the section that blockhosts.py will modify.  Make sure you allow your own IP blocks first and any trusted IPs so they don&#039;t get blocked accidentally:&lt;br /&gt;
&lt;br /&gt;
&lt;strong&gt;GOTCHA LOOKOUT!&lt;/strong&gt;&lt;br /&gt;
One gotcha to watch out for in this is the line:&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;bb-code-title&quot;&gt;CODE:&lt;/div&gt;&lt;div class=&quot;bb-code&quot;&gt;ALL&amp;#160;&amp;#58;&amp;#160;ALL&amp;#160;&amp;#58;&amp;#160;allow&lt;/div&gt;&lt;br /&gt;
&lt;br /&gt;
You &lt;strong&gt;MUST&lt;/strong&gt; remove this line - replace it with your IP block instead so you don&#039;t get locked out from your own address range.  If this line isn&#039;t removed/commented out, anything below it just isn&#039;t read/executed and blockhosts won&#039;t work.&lt;br /&gt;
&lt;br /&gt;
This is how my /etc/hosts.allow looks:&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;bb-code-title&quot;&gt;CODE:&lt;/div&gt;&lt;div class=&quot;bb-code&quot;&gt;#######################################################################&lt;br /&gt;
#&amp;#160;blockhosts&lt;br /&gt;
#######################################################################&lt;br /&gt;
#&amp;#160;----&lt;br /&gt;
#&amp;#160;see&amp;#160;&quot;man&amp;#160;5&amp;#160;hosts_access&quot;&amp;#160;for&amp;#160;details&amp;#160;of&amp;#160;the&amp;#160;format&amp;#160;of&amp;#160;IP&amp;#160;addresses,&lt;br /&gt;
#services,&amp;#160;allow/deny&amp;#160;options.&amp;#160;Also&amp;#160;see&amp;#160;&quot;man&amp;#160;hosts_options&quot;&lt;br /&gt;
#order&amp;#160;of&amp;#160;lines&amp;#160;in&amp;#160;this&amp;#160;file&amp;#160;is&amp;#160;important,&amp;#160;first&amp;#160;matched&amp;#160;IP&amp;#160;address&amp;#160;line&lt;br /&gt;
#is&amp;#160;rule&amp;#160;applied&amp;#160;by&amp;#160;hosts_access&lt;br /&gt;
#&lt;br /&gt;
#&amp;#160;permanent&amp;#160;whitelist&amp;#160;addresses&amp;#160;-&amp;#160;these&amp;#160;should&amp;#160;always&amp;#160;be&amp;#160;allowed&amp;#160;access&lt;br /&gt;
&lt;br /&gt;
ALL&amp;#160;&amp;#58;&amp;#160;213.152.51.192/255.255.255.248&amp;#160;&amp;#58;&amp;#160;allow&lt;br /&gt;
#&amp;#160;ALL&amp;#58;&amp;#160;127.0.0.1&amp;#160;&amp;#160;&amp;#58;&amp;#160;allow&lt;br /&gt;
#&amp;#160;ALL&amp;#58;&amp;#160;192.168.0.&amp;#160;&amp;#58;&amp;#160;allow&lt;br /&gt;
&lt;br /&gt;
#&amp;#160;permanent&amp;#160;blacklist&amp;#160;addresses&amp;#160;-&amp;#160;these&amp;#160;should&amp;#160;always&amp;#160;be&amp;#160;denied&amp;#160;access&lt;br /&gt;
&lt;br /&gt;
#&amp;#160;ALL&amp;#58;&amp;#160;10.&amp;#160;&amp;#160;&amp;#58;&amp;#160;deny&lt;br /&gt;
#&amp;#160;ALL&amp;#58;&amp;#160;192.&amp;#160;&amp;#58;&amp;#160;deny&lt;br /&gt;
#&amp;#160;ALL&amp;#58;&amp;#160;172.&amp;#160;&amp;#58;&amp;#160;deny&lt;br /&gt;
&lt;br /&gt;
#&amp;#160;----------------------------------------&lt;br /&gt;
#&amp;#160;next&amp;#160;section&amp;#160;is&amp;#160;the&amp;#160;blockhosts&amp;#160;section&amp;#160;-&amp;#160;it&amp;#160;will&amp;#160;add/delete&amp;#160;entries&amp;#160;in&lt;br /&gt;
#&amp;#160;between&amp;#160;the&amp;#160;two&amp;#160;marker&amp;#160;lines&amp;#160;&amp;#40;#----&amp;#160;BlockHosts&amp;#160;Additions&amp;#41;&lt;br /&gt;
&lt;br /&gt;
#----&amp;#160;BlockHosts&amp;#160;Additions&lt;br /&gt;
#----&amp;#160;BlockHosts&amp;#160;Additions&lt;br /&gt;
&lt;br /&gt;
#&amp;#160;----------------------------------------&lt;br /&gt;
#&amp;#160;finally,&amp;#160;the&amp;#160;command&amp;#160;to&amp;#160;execute&amp;#160;the&amp;#160;blockhosts&amp;#160;script,&amp;#160;based&amp;#160;on&lt;br /&gt;
#&amp;#160;connection&amp;#160;to&amp;#160;particular&amp;#160;service&amp;#160;or&amp;#160;services,&amp;#160;for&amp;#160;example,&amp;#160;for&lt;br /&gt;
#&amp;#160;sshd&amp;#160;and&amp;#160;proftpd&amp;#160;-&amp;#160;if&amp;#160;using&amp;#160;vsftpd,&amp;#160;pure-ftpd,&amp;#160;be&amp;#160;sure&amp;#160;to&amp;#160;use&amp;#160;those&lt;br /&gt;
#&amp;#160;words&amp;#160;instead&amp;#58;&lt;br /&gt;
&lt;br /&gt;
sshd,&amp;#160;proftpd&amp;#58;&amp;#160;ALL&amp;#58;&amp;#160;spawn&amp;#160;&amp;#40;/usr/local/bin/blockhosts.py&amp;#160;--verbose&amp;#160;--echo&amp;#160;&quot;%c-%s&quot;&amp;#160;&amp;#62;&amp;#62;&amp;#160;/var/log/blockhosts.log&amp;#160;2&amp;#62;&amp;amp;1&amp;#160;&amp;#41;&amp;amp;&amp;#160;&amp;#58;&amp;#160;allow&lt;br /&gt;
&lt;br /&gt;
#&amp;#160;remove&amp;#58;&amp;#160;&amp;#160;&amp;#160;&amp;#62;&amp;#62;&amp;#160;/var/log/blockhosts.log&amp;#160;2&amp;#62;&amp;amp;1&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;if&amp;#160;logging&amp;#160;to&lt;br /&gt;
#&amp;#160;blockhosts.log&amp;#160;is&amp;#160;not&amp;#160;needed&amp;#160;-&amp;#160;it&amp;#160;will&amp;#160;still&amp;#160;log&amp;#160;to&amp;#160;syslog&amp;#160;&amp;#40;minimally&amp;#41;&lt;br /&gt;
#&amp;#160;see&amp;#160;examples&amp;#160;below&lt;br /&gt;
#&amp;#160;--&lt;br /&gt;
#&amp;#160;See&amp;#160;&quot;man&amp;#160;hosts.allow&quot;&amp;#160;for&amp;#160;info&amp;#160;on&amp;#160;%c&amp;#160;and&amp;#160;%s&amp;#160;identifiers&lt;br /&gt;
#----&lt;br /&gt;
#&amp;#160;for&amp;#160;non-verbose,&amp;#160;with&amp;#160;identification,&amp;#160;to&amp;#160;syslog&amp;#160;only&amp;#160;&amp;#40;/var/log/messages&amp;#41;&amp;#58;&lt;br /&gt;
#sshd,&amp;#160;proftpd,&amp;#160;in.proftpd&amp;#58;&amp;#160;ALL&amp;#58;&amp;#160;spawn&amp;#160;/usr/bin/blockhosts.py&amp;#160;--echo&amp;#160;&quot;%c-%s&quot;&amp;#160;&amp;amp;&amp;#160;&amp;#58;&amp;#160;allow&lt;br /&gt;
#----&lt;br /&gt;
#&amp;#160;minimal&amp;#160;logging,&amp;#160;to&amp;#160;syslog&amp;#160;&amp;#40;usually&amp;#160;goes&amp;#160;to&amp;#160;/var/log/messages&amp;#41;&amp;#58;&lt;br /&gt;
#sshd,&amp;#160;proftpd,&amp;#160;in.proftpd&amp;#58;&amp;#160;ALL&amp;#58;&amp;#160;spawn&amp;#160;/usr/bin/blockhosts.py&amp;#160;&amp;amp;&amp;#160;&amp;#58;&amp;#160;allow&lt;br /&gt;
#----&lt;br /&gt;
#&amp;#160;To&amp;#160;test&amp;#160;hosts.allow,&amp;#160;and&amp;#160;to&amp;#160;find&amp;#160;out&amp;#160;exact&amp;#160;names&amp;#160;of&amp;#160;SSH/FTP&amp;#160;services,&lt;br /&gt;
#&amp;#160;add&amp;#160;this&amp;#160;line&amp;#160;to&amp;#160;the&amp;#160;beginning&amp;#160;of&amp;#160;hosts.allow,&amp;#160;use&amp;#160;ssh/ftp&amp;#160;to&amp;#160;connect&lt;br /&gt;
#&amp;#160;to&amp;#160;your&amp;#160;server,&amp;#160;and&amp;#160;then&amp;#160;look&amp;#160;at&amp;#160;the&amp;#160;log&amp;#160;&amp;#40;/var/log/messages&amp;#160;or&lt;br /&gt;
#&amp;#160;blockhosts.log&amp;#41;&amp;#160;to&amp;#160;see&amp;#160;the&amp;#160;name&amp;#160;of&amp;#160;the&amp;#160;invoked&amp;#160;service.&lt;br /&gt;
#&amp;#160;IMPORTANT&amp;#58;&amp;#160;after&amp;#160;your&amp;#160;test&amp;#160;is&amp;#160;done,&amp;#160;remove&amp;#160;this&amp;#160;line&amp;#160;from&amp;#160;hosts.allow!&lt;br /&gt;
#&amp;#160;Otherwise&amp;#160;everyone&amp;#160;will&amp;#160;always&amp;#160;have&amp;#160;access.&lt;br /&gt;
#ALL&amp;#160;&amp;#58;&amp;#160;ALL&amp;#58;&amp;#160;spawn&amp;#160;&amp;#40;/usr/bin/blockhosts.py&amp;#160;--verbose&amp;#160;--echo&amp;#160;&quot;%c-%s&quot;&amp;#160;&amp;#62;&amp;#62;&amp;#160;/var/log/blockhosts.log&amp;#160;2&amp;#62;&amp;amp;1&amp;#160;&amp;#41;&amp;amp;&amp;#160;&amp;#58;&amp;#160;allow&lt;br /&gt;
#######################################################################&lt;br /&gt;
#&amp;#160;blockhosts&lt;br /&gt;
#######################################################################&lt;/div&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-weight:bold&quot;&gt;Important Note for ProFTPD users:&lt;/span&gt;&lt;br /&gt;
The following sections describes the configuration needed when using proftpd via inetd.  If you are using ProFTPD in standalone mode, you need to use the proftpd mod_wrap/mod_wrap_file functionality to have proftpd read and honour the TCP_WRAPPERS//etc/hosts.allow file(s) when denying/allowing hosts.  Additionally you need to specifiy the configure flag --enable-wrapper-options when building proftpd.  For a heavily used server, this might be worth doing but personally I don&#039;t get that many connections that I need to worry about inetd being overloaded so I can just go down the (easier to configure for blockhosts) inetd path.&lt;br /&gt;
&lt;br /&gt;
&lt;li&gt;Ensure proftpd is configured to run correctly via inetd.&lt;br /&gt;
&lt;br /&gt;
Edit and save /usr/local/etc/proftpd.conf to read:&lt;br /&gt;
&lt;div class=&quot;bb-code-title&quot;&gt;CODE:&lt;/div&gt;&lt;div class=&quot;bb-code&quot;&gt;ServerType&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;inetd&lt;/div&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-weight:bold&quot;&gt;Important:&lt;/span&gt; remember to delete or rename /usr/local/etc/rc.d/proftpd.sh so it&#039;s not run at boot time - the proftpd daemon doesn&#039;t need to be started at boot if you&#039;re using inetd, inetd handles all the proftpd connections, see below:&lt;br /&gt;
&lt;br /&gt;
Edit and save /etc/inetd.conf to read:&lt;br /&gt;
&lt;div class=&quot;bb-code-title&quot;&gt;CODE:&lt;/div&gt;&lt;div class=&quot;bb-code&quot;&gt;ftp&amp;#160;stream&amp;#160;&amp;#160;tcp&amp;#160;nowait&amp;#160;&amp;#160;root&amp;#160;&amp;#160;&amp;#160;&amp;#160;/usr/local/sbin/in.proftpd&amp;#160;proftpd&lt;/div&gt;&lt;br /&gt;
&lt;br /&gt;
then restart inetd:&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;bb-code-title&quot;&gt;CODE:&lt;/div&gt;&lt;div class=&quot;bb-code&quot;&gt;root@users&amp;#160;/usr/local/etc#&amp;#160;kill&amp;#160;-HUP&amp;#160;`cat&amp;#160;/var/run/inetd.pid&amp;#160;`&lt;/div&gt;&lt;br /&gt;
This forces inetd to restart, rereading the config file changes made to /etc/inetd.conf.  ftp connections will now be handled by proftpd via inetd.&lt;br /&gt;
&lt;/ol&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
We&#039;re now ready to run blockhosts.py for the first time.  BlockHosts will parse each logfile mentioned in blockhosts.cfg and check for any brute force attacks and if it finds any, blocks will be added to the /etc/hosts.allow file.  &lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-weight:bold&quot;&gt;Note:&lt;/span&gt; This initial check does not take into account the period over which failed logins took place, so any IP that has more than the default 7 failed login entries will look like a brute force attacker.  However, the ban BlockHosts adds will only last for the default 12 hours so this shouldn&#039;t cause a huge issue - just be aware of this and check the IPs that are added on the first run.&lt;br /&gt;
&lt;br /&gt;
For the very first time it&#039;s a good idea to try a &#039;dry run&#039; just to see what blockhosts finds and what it&#039;d do, without actually doing anything to the /etc/hosts.allow file.  To do this, run blockhosts with the &#039;--dry-run&#039; flag:&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;bb-code-title&quot;&gt;CODE:&lt;/div&gt;&lt;div class=&quot;bb-code&quot;&gt;root@users&amp;#160;/usr/local/etc#&amp;#160;/usr/local/bin/blockhosts.py&amp;#160;--verbose&amp;#160;--dry-run&lt;br /&gt;
blockhosts&amp;#160;1.0.5&amp;#160;started&amp;#58;&amp;#160;2006-12-30&amp;#160;14&amp;#58;15&amp;#58;30&lt;br /&gt;
&amp;#160;...&amp;#160;will&amp;#160;discard&amp;#160;all&amp;#160;host&amp;#160;entries&amp;#160;older&amp;#160;than&amp;#160;&amp;#160;2006-12-30&amp;#160;02&amp;#58;15&lt;br /&gt;
&amp;#160;...&amp;#160;load&amp;#160;blockfile&amp;#58;&amp;#160;/etc/hosts.allow&lt;br /&gt;
&amp;#160;...&amp;#160;found&amp;#160;both&amp;#160;markers,&amp;#160;count&amp;#160;of&amp;#160;hosts&amp;#160;being&amp;#160;watched&amp;#58;&amp;#160;0&lt;br /&gt;
&amp;#160;&amp;#160;Warning&amp;#58;&amp;#160;no&amp;#160;offset&amp;#160;found,&amp;#160;will&amp;#160;read&amp;#160;from&amp;#160;beginning&amp;#160;in&amp;#160;logfile&amp;#58;&amp;#160;/var/log/auth.log&lt;br /&gt;
&amp;#160;...&amp;#160;securelog,&amp;#160;loading&amp;#160;file,&amp;#160;offset&amp;#58;&amp;#160;/var/log/auth.log&amp;#160;0&lt;br /&gt;
&amp;#160;&amp;#160;Warning&amp;#58;&amp;#160;no&amp;#160;offset&amp;#160;found,&amp;#160;will&amp;#160;read&amp;#160;from&amp;#160;beginning&amp;#160;in&amp;#160;logfile&amp;#58;&amp;#160;/var/log/ftp.log&lt;br /&gt;
&amp;#160;...&amp;#160;securelog,&amp;#160;loading&amp;#160;file,&amp;#160;offset&amp;#58;&amp;#160;/var/log/ftp.log&amp;#160;0&lt;br /&gt;
&amp;#160;...&amp;#160;updates&amp;#58;&amp;#160;counts&amp;#58;&amp;#160;hosts&amp;#160;to&amp;#160;block&amp;#58;&amp;#160;9;&amp;#160;hosts&amp;#160;being&amp;#160;watched&amp;#58;&amp;#160;21&lt;br /&gt;
#----&amp;#160;BlockHosts&amp;#160;Additions&lt;br /&gt;
ALL&amp;#58;&amp;#160;&amp;#160;203.88.192.225&amp;#160;&amp;#58;&amp;#160;deny&lt;br /&gt;
ALL&amp;#58;&amp;#160;&amp;#160;&amp;#160;&amp;#160;200.71.192.7&amp;#160;&amp;#58;&amp;#160;deny&lt;br /&gt;
ALL&amp;#58;&amp;#160;&amp;#160;212.227.81.146&amp;#160;&amp;#58;&amp;#160;deny&lt;br /&gt;
ALL&amp;#58;&amp;#160;&amp;#160;&amp;#160;&amp;#160;218.25.62.75&amp;#160;&amp;#58;&amp;#160;deny&lt;br /&gt;
ALL&amp;#58;&amp;#160;&amp;#160;200.46.108.164&amp;#160;&amp;#58;&amp;#160;deny&lt;br /&gt;
ALL&amp;#58;&amp;#160;&amp;#160;&amp;#160;&amp;#160;201.57.163.2&amp;#160;&amp;#58;&amp;#160;deny&lt;br /&gt;
ALL&amp;#58;&amp;#160;&amp;#160;205.129.191.11&amp;#160;&amp;#58;&amp;#160;deny&lt;br /&gt;
ALL&amp;#58;&amp;#160;&amp;#160;&amp;#160;&amp;#160;200.68.51.91&amp;#160;&amp;#58;&amp;#160;deny&lt;br /&gt;
ALL&amp;#58;&amp;#160;&amp;#160;&amp;#160;&amp;#160;82.38.68.217&amp;#160;&amp;#58;&amp;#160;deny&lt;br /&gt;
&lt;br /&gt;
#bh&amp;#58;&amp;#160;ip&amp;#58;&amp;#160;&amp;#160;&amp;#160;85.184.10.200&amp;#160;&amp;#58;&amp;#160;&amp;#160;&amp;#160;1&amp;#160;&amp;#58;&amp;#160;2006-12-30-14-15&lt;br /&gt;
#bh&amp;#58;&amp;#160;ip&amp;#58;&amp;#160;&amp;#160;84.158.231.209&amp;#160;&amp;#58;&amp;#160;&amp;#160;&amp;#160;1&amp;#160;&amp;#58;&amp;#160;2006-12-30-14-15&lt;br /&gt;
#bh&amp;#58;&amp;#160;ip&amp;#58;&amp;#160;&amp;#160;&amp;#160;&amp;#160;82.38.68.217&amp;#160;&amp;#58;&amp;#160;&amp;#160;11&amp;#160;&amp;#58;&amp;#160;2006-12-30-14-15&lt;br /&gt;
#bh&amp;#58;&amp;#160;ip&amp;#58;&amp;#160;&amp;#160;&amp;#160;&amp;#160;82.153.28.16&amp;#160;&amp;#58;&amp;#160;&amp;#160;&amp;#160;2&amp;#160;&amp;#58;&amp;#160;2006-12-30-14-15&lt;br /&gt;
#bh&amp;#58;&amp;#160;ip&amp;#58;&amp;#160;&amp;#160;&amp;#160;67.113.225.66&amp;#160;&amp;#58;&amp;#160;&amp;#160;&amp;#160;1&amp;#160;&amp;#58;&amp;#160;2006-12-30-14-15&lt;br /&gt;
#bh&amp;#58;&amp;#160;ip&amp;#58;&amp;#160;&amp;#160;&amp;#160;59.108.34.228&amp;#160;&amp;#58;&amp;#160;&amp;#160;&amp;#160;2&amp;#160;&amp;#58;&amp;#160;2006-12-30-14-15&lt;br /&gt;
#bh&amp;#58;&amp;#160;ip&amp;#58;&amp;#160;&amp;#160;222.68.192.132&amp;#160;&amp;#58;&amp;#160;&amp;#160;&amp;#160;2&amp;#160;&amp;#58;&amp;#160;2006-12-30-14-15&lt;br /&gt;
#bh&amp;#58;&amp;#160;ip&amp;#58;&amp;#160;&amp;#160;&amp;#160;&amp;#160;218.25.62.75&amp;#160;&amp;#58;&amp;#160;&amp;#160;20&amp;#160;&amp;#58;&amp;#160;2006-12-30-14-15&lt;br /&gt;
#bh&amp;#58;&amp;#160;ip&amp;#58;&amp;#160;&amp;#160;217.83.162.157&amp;#160;&amp;#58;&amp;#160;&amp;#160;&amp;#160;1&amp;#160;&amp;#58;&amp;#160;2006-12-30-14-15&lt;br /&gt;
#bh&amp;#58;&amp;#160;ip&amp;#58;&amp;#160;&amp;#160;212.227.81.146&amp;#160;&amp;#58;&amp;#160;29499&amp;#160;&amp;#58;&amp;#160;2006-12-30-14-15&lt;br /&gt;
#bh&amp;#58;&amp;#160;ip&amp;#58;&amp;#160;&amp;#160;&amp;#160;210.1.132.178&amp;#160;&amp;#58;&amp;#160;&amp;#160;&amp;#160;4&amp;#160;&amp;#58;&amp;#160;2006-12-30-14-15&lt;br /&gt;
#bh&amp;#58;&amp;#160;ip&amp;#58;&amp;#160;&amp;#160;205.129.191.11&amp;#160;&amp;#58;&amp;#160;&amp;#160;20&amp;#160;&amp;#58;&amp;#160;2006-12-30-14-15&lt;br /&gt;
#bh&amp;#58;&amp;#160;ip&amp;#58;&amp;#160;&amp;#160;&amp;#160;204.141.87.14&amp;#160;&amp;#58;&amp;#160;&amp;#160;&amp;#160;3&amp;#160;&amp;#58;&amp;#160;2006-12-30-14-15&lt;br /&gt;
#bh&amp;#58;&amp;#160;ip&amp;#58;&amp;#160;&amp;#160;203.88.192.225&amp;#160;&amp;#58;&amp;#160;448&amp;#160;&amp;#58;&amp;#160;2006-12-30-14-15&lt;br /&gt;
#bh&amp;#58;&amp;#160;ip&amp;#58;&amp;#160;&amp;#160;202.108.40.109&amp;#160;&amp;#58;&amp;#160;&amp;#160;&amp;#160;1&amp;#160;&amp;#58;&amp;#160;2006-12-30-14-15&lt;br /&gt;
#bh&amp;#58;&amp;#160;ip&amp;#58;&amp;#160;&amp;#160;&amp;#160;&amp;#160;201.57.163.2&amp;#160;&amp;#58;&amp;#160;2867&amp;#160;&amp;#58;&amp;#160;2006-12-30-14-15&lt;br /&gt;
#bh&amp;#58;&amp;#160;ip&amp;#58;&amp;#160;&amp;#160;&amp;#160;&amp;#160;200.71.192.7&amp;#160;&amp;#58;&amp;#160;761&amp;#160;&amp;#58;&amp;#160;2006-12-30-14-15&lt;br /&gt;
#bh&amp;#58;&amp;#160;ip&amp;#58;&amp;#160;&amp;#160;&amp;#160;&amp;#160;200.68.51.91&amp;#160;&amp;#58;&amp;#160;&amp;#160;10&amp;#160;&amp;#58;&amp;#160;2006-12-30-14-15&lt;br /&gt;
#bh&amp;#58;&amp;#160;ip&amp;#58;&amp;#160;&amp;#160;200.46.108.164&amp;#160;&amp;#58;&amp;#160;170&amp;#160;&amp;#58;&amp;#160;2006-12-30-14-15&lt;br /&gt;
#bh&amp;#58;&amp;#160;ip&amp;#58;&amp;#160;&amp;#160;200.105.255.90&amp;#160;&amp;#58;&amp;#160;&amp;#160;&amp;#160;7&amp;#160;&amp;#58;&amp;#160;2006-12-30-14-15&lt;br /&gt;
#bh&amp;#58;&amp;#160;ip&amp;#58;&amp;#160;&amp;#160;152.104.125.14&amp;#160;&amp;#58;&amp;#160;&amp;#160;&amp;#160;3&amp;#160;&amp;#58;&amp;#160;2006-12-30-14-15&lt;/div&gt;&lt;br /&gt;
&lt;br /&gt;
From this you can see nicely what blockhosts makes of the service logfiles and the addresses that have tried to connect unsuccessfully.  On my host, as you can see above, there are a few that are obviously dodgy (I would only expect a max of maybe 8 connections per ip per month, so clearly 29,499 connections is just &lt;span style=&quot;font-style:italic&quot;&gt;wrong&lt;/span&gt;!).&lt;br /&gt;
&lt;br /&gt;
Once you&#039;re happy that the output is correct, run blockhosts again without the &#039;--dry-run&#039; flag and the /etc/hosts.allow file will be modified.  Also from now on the logfiles will only be read from the last recorded offset which saves a lot of time if your logfiles are very big.&lt;br /&gt;
&lt;br /&gt;
Big thanks to the BlockHosts author Avinash Chopde ! 
    </content:encoded>

    <pubDate>Sat, 30 Dec 2006 11:52:15 +0000</pubDate>
    <guid isPermaLink="false">http://freebsd.munk.me.uk/archives/209-guid.html</guid>
    <creativeCommons:license>http://creativecommons.org/licenses/by/2.5/</creativeCommons:license>
</item>
<item>
    <title>FTP Transfer Failure With A Firewall</title>
    <link>http://freebsd.munk.me.uk/archives/78-FTP-Transfer-Failure-With-A-Firewall.html</link>
            <category>FTP</category>
    
    <comments>http://freebsd.munk.me.uk/archives/78-FTP-Transfer-Failure-With-A-Firewall.html#comments</comments>
    <wfw:comment>http://freebsd.munk.me.uk/wfwcomment.php?cid=78</wfw:comment>

    <slash:comments>3</slash:comments>
    <wfw:commentRss>http://freebsd.munk.me.uk/rss.php?version=2.0&amp;type=comments&amp;cid=78</wfw:commentRss>
    

    <author>nospam@example.com (munk)</author>
    <content:encoded>
    This is a question that crops up fairly often about why remote ftp clients using passive data transfer mode can&#039;t connect properly to the FTP server whilst a firewall is in effect.&lt;br /&gt;
&lt;br /&gt;
See the extended article for a discussion of the problem.&lt;br /&gt;
&lt;br /&gt;
 &lt;br /&gt;&lt;a href=&quot;http://freebsd.munk.me.uk/archives/78-FTP-Transfer-Failure-With-A-Firewall.html#extended&quot;&gt;Continue reading &quot;FTP Transfer Failure With A Firewall&quot;&lt;/a&gt;
    </content:encoded>

    <pubDate>Thu, 29 Jan 2004 13:33:02 +0000</pubDate>
    <guid isPermaLink="false">http://freebsd.munk.me.uk/archives/78-guid.html</guid>
    <creativeCommons:license>http://creativecommons.org/licenses/by/2.5/</creativeCommons:license>
</item>
<item>
    <title>ProFTPD Delay Whilst Authenticating</title>
    <link>http://freebsd.munk.me.uk/archives/73-ProFTPD-Delay-Whilst-Authenticating.html</link>
            <category>FTP</category>
    
    <comments>http://freebsd.munk.me.uk/archives/73-ProFTPD-Delay-Whilst-Authenticating.html#comments</comments>
    <wfw:comment>http://freebsd.munk.me.uk/wfwcomment.php?cid=73</wfw:comment>

    <slash:comments>1</slash:comments>
    <wfw:commentRss>http://freebsd.munk.me.uk/rss.php?version=2.0&amp;type=comments&amp;cid=73</wfw:commentRss>
    

    <author>nospam@example.com (munk)</author>
    <content:encoded>
    When connecting to the proftpd server, a noticeable delay of around 5 seconds can be seen.  To fix this I switched off ident lookups in proftpd.conf and all was fine:&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;bb-code-title&quot;&gt;CODE:&lt;/div&gt;&lt;div class=&quot;bb-code&quot;&gt;#&amp;#160;Don&#039;t&amp;#160;do&amp;#160;ident&amp;#160;lookups&amp;#58;&lt;br /&gt;
IdentLookups&amp;#160;off&lt;/div&gt;&lt;br /&gt;
&lt;br /&gt;
Simple :P 
    </content:encoded>

    <pubDate>Wed, 28 Jan 2004 23:49:00 +0000</pubDate>
    <guid isPermaLink="false">http://freebsd.munk.me.uk/archives/73-guid.html</guid>
    <creativeCommons:license>http://creativecommons.org/licenses/by/2.5/</creativeCommons:license>
</item>

</channel>
</rss>