{"id":785,"date":"2011-08-24T07:58:41","date_gmt":"2011-08-24T12:58:41","guid":{"rendered":"http:\/\/it.thelibrarie.com\/weblog\/?p=785"},"modified":"2015-07-01T15:40:55","modified_gmt":"2015-07-01T20:40:55","slug":"fail2ban-ubuntu-ssh-vsftp","status":"publish","type":"post","link":"https:\/\/it.thelibrarie.com\/weblog\/2011\/08\/fail2ban-ubuntu-ssh-vsftp\/","title":{"rendered":"Fail2ban Ubuntu SSH VSFTP"},"content":{"rendered":"<p>I like security.  The more control I have over a network or system the better I feel.  So when I had to push out a couple of secure FTP sites for clients, I had to make sure that they couldn&#8217;t be broken into.<\/p>\n<p>First I started with Ubuntu 10.04.3LTS LAMP installation.  The rest you can see below:<\/p>\n<p>Update Linux<\/p>\n<blockquote><p><code>apt-get update<\/code><br \/>\n<code>apt-get upgrade<\/code><br \/>\n<code>apt-get install build-essential<\/code><br \/>\n<code>apt-get dist-upgrade<\/code><br \/>\n<code>reboot<\/code><\/p><\/blockquote>\n<p>Remove anything unneeded<\/p>\n<blockquote><p><code>apt-get autoremove<\/code><\/p><\/blockquote>\n<p>I installed SSH access to one external-facing system, on a completely separate network, but have edited the allowed hosts to be only my personal public IP.  But it&#8217;s still a good idea to stop people from trying and filling up the logs.  I also installed VSFTP on two external-facing systems &#8211; it is these systems that I worry most about.<\/p>\n<p>Install fail2ban<\/p>\n<blockquote><p><code>apt-get install fail2ban<\/code><\/p><\/blockquote>\n<p>Edit the configuration<\/p>\n<blockquote><p><code>nano \/etc\/fail2ban\/jail.local<\/code><\/p><\/blockquote>\n<p>Now I put the following in there:<\/p>\n<blockquote><p>[DEFAULT]<br \/>\n# &#8220;ignoreip&#8221; can be an IP address, a CIDR mask or a DNS host<br \/>\nignoreip = 127.0.0.1 192.168.0.99<br \/>\nbantime  = 60<br \/>\nmaxretry = 3<br \/>\nbackend = polling<br \/>\n# Destination email address used solely for the interpolations in<br \/>\n# jail.{conf,local} configuration files.<br \/>\ndestemail = root@localhost<br \/>\n# Default action to take: ban only<br \/>\naction = iptables[name=%(__name__)s, port=%(port)s]<br \/>\n[ssh]<br \/>\nenabled = true<br \/>\nport    = ssh<br \/>\nfilter  = sshd<br \/>\nlogpath  = \/var\/log\/auth.log<br \/>\nmaxretry = 5<br \/>\n[vsftpd]<br \/>\nenabled  = false<br \/>\nport     = ftp,ftp-data,ftps,ftps-data<br \/>\nfilter   = vsftpd<br \/>\nlogpath  = \/var\/log\/vsftpd.log<br \/>\nmaxretry = 5<\/p><\/blockquote>\n<p>Restart the Fail2ban service<\/p>\n<blockquote><p><code>\/etc\/init.d\/fail2ban restart<\/code><\/p><\/blockquote>\n<p>I checked to see if SSH would be &#8220;banned&#8221; by trying to connect from another system several times to the fail2ban system (see actions in BOLD):<br \/>\n<code>tail -f \/var\/log\/fail2ban.log<\/code><\/p>\n<blockquote><p>2011-08-24 07:40:29,300 fail2ban.jail   : INFO   Jail &#8216;ssh&#8217; uses poller<br \/>\n2011-08-24 07:40:29,330 fail2ban.filter : INFO   Added logfile = \/var\/log\/auth.log<br \/>\n2011-08-24 07:40:29,332 fail2ban.filter : INFO   Set maxRetry = 5<br \/>\n2011-08-24 07:40:29,336 fail2ban.filter : INFO   Set findtime = 600<br \/>\n2011-08-24 07:40:29,337 fail2ban.actions: INFO   Set banTime = 60<br \/>\n2011-08-24 07:40:29,481 fail2ban.jail   : INFO   Jail &#8216;ssh&#8217; started<br \/>\n<strong>2011-08-24 07:40:39,561 fail2ban.actions: WARNING [ssh] Ban 192.168.0.253<\/strong><br \/>\n<strong>2011-08-24 07:41:39,816 fail2ban.actions: WARNING [ssh] Unban 192.168.0.253<\/strong>\n<\/p><\/blockquote>\n<p>You can verify that the ban is active by listing out your iptables<br \/>\n<code>iptables -L<\/code><\/p>\n<p>Next I&#8217;ll verify that it works on vsftp.<br \/>\nEdit the fail2ban local jail<br \/>\n<code>nano \/etc\/fail2ban\/jail.local<\/code><br \/>\nChange the enabled to enabled = true<br \/>\nRestart the fail2ban service<br \/>\n<code>\/etc\/init.d\/fail2ban restart<\/code><\/p>\n<p>Then I ran the regex checker<br \/>\nfail2ban-regex \/var\/log\/vsftpd.log \/etc\/fail2ban\/filter.d\/vsftpd.conf<br \/>\nWhich gave me 0 results.<\/p>\n<p>Edit the failregex configuration<br \/>\n<code>nano \/etc\/fail2ban\/filter.d\/vsftpd.conf<\/code><br \/>\nI changed from FAIL LOGIN to CONNECT<br \/>\nSave and quit, then restart fail2ban<\/p>\n<blockquote><p>2011-08-24 08:17:19,564 fail2ban.actions: WARNING [vsftpd] Ban 192.168.0.115<br \/>\n2011-08-24 08:18:19,660 fail2ban.actions: WARNING [vsftpd] Unban 192.168.0.115<\/p><\/blockquote>\n<p>***EDIT***<br \/>\nI had a few bots that were trying to get access to directories that didn&#8217;t exist.<\/p>\n<p>In my \/etc\/fail2ban\/jail.local<\/p>\n<blockquote><p>\n[owncloud]<br \/>\nenabled = true<br \/>\nport = http,https<br \/>\nfilter = apache-owncloud<br \/>\nlogpath = \/var\/log\/apache2\/error.log<br \/>\nmaxretry = 3<br \/>\nbantime = 240\n<\/p><\/blockquote>\n<p>In my \/etc\/fail2ban\/filter.d\/apache-owncloud.conf<\/p>\n<blockquote><p>\n[Definition]<br \/>\nfailregex = \\[client <HOST>\\] (File does not exist|script not found or unable to stat): [^ ]*\/([^ ]*\\.asp|[^ ]*\\.dll|[^ ]*\\.exe|admin|Admin|Ads|ads|apps|archive|awstats|b0ard|bin|blog|board|cgi|clan|cms|community|cube|database|datenbank$<\/p>\n<p>ignoreregex =\n<\/p><\/blockquote>\n<p><strong>Unblock an existing entry<\/strong><br \/>\nWe all know that you can use iptables -L to find the entry and then -D to delete it. Fail2ban doesn&#8217;t really like that.<\/p>\n<p><code>fail2ban-client set JAIL unbanip MYIP<\/code><br \/>\nIf you forgot your jail name (haha) you can list them all out:<br \/>\n<code>fail2ban-client status<\/code><\/p>\n","protected":false},"excerpt":{"rendered":"<p>I like security. The more control I have over a network or system the better I feel. So when I had to push out a couple of secure FTP sites for clients, I had to make sure that they couldn&#8217;t be broken into. First I started with Ubuntu 10.04.3LTS LAMP installation. The rest you can &hellip; <a href=\"https:\/\/it.thelibrarie.com\/weblog\/2011\/08\/fail2ban-ubuntu-ssh-vsftp\/\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">Fail2ban Ubuntu SSH VSFTP<\/span> <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[7],"tags":[],"class_list":["post-785","post","type-post","status-publish","format-standard","hentry","category-linux"],"_links":{"self":[{"href":"https:\/\/it.thelibrarie.com\/weblog\/wp-json\/wp\/v2\/posts\/785","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/it.thelibrarie.com\/weblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/it.thelibrarie.com\/weblog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/it.thelibrarie.com\/weblog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/it.thelibrarie.com\/weblog\/wp-json\/wp\/v2\/comments?post=785"}],"version-history":[{"count":10,"href":"https:\/\/it.thelibrarie.com\/weblog\/wp-json\/wp\/v2\/posts\/785\/revisions"}],"predecessor-version":[{"id":1273,"href":"https:\/\/it.thelibrarie.com\/weblog\/wp-json\/wp\/v2\/posts\/785\/revisions\/1273"}],"wp:attachment":[{"href":"https:\/\/it.thelibrarie.com\/weblog\/wp-json\/wp\/v2\/media?parent=785"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/it.thelibrarie.com\/weblog\/wp-json\/wp\/v2\/categories?post=785"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/it.thelibrarie.com\/weblog\/wp-json\/wp\/v2\/tags?post=785"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}