{"id":660,"date":"2007-06-03T09:45:00","date_gmt":"2007-06-03T09:45:00","guid":{"rendered":"https:\/\/jasonmartin.info\/?p=660"},"modified":"2007-06-03T09:45:00","modified_gmt":"2007-06-03T09:45:00","slug":"howto-slow-down-and-log-bruteforce-attacks-on-your-debian-system","status":"publish","type":"post","link":"https:\/\/www.jasonmartin.info\/index.php\/2007\/06\/03\/howto-slow-down-and-log-bruteforce-attacks-on-your-debian-system\/","title":{"rendered":"HOWTO: Slow down and log bruteforce attacks on your Debian system"},"content":{"rendered":"\n<p class=\"has-text-align-left\">This howto is going to assume you have a working Debian or Debian based system currently running. It is also intended to be copied and pasted directly into your telnet\/ssh window.<\/p>\n\n\n\n<p>The package I am going to be using is called fail2ban. Fail2ban scans log files and bans IP addresses that produce too many failed login attempts. It then updates firewall rules to reject the attackers IP address.<\/p>\n\n\n\n<p><strong>Step 1<\/strong>: Installing the fail2ban package<\/p>\n\n\n\n<p>Type or copy and paste the following into your server.<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\"><p>apt-get install fail2ban<\/p><\/blockquote>\n\n\n\n<p>Once this is done, you are now setup and now you have to setup the configuration files.<\/p>\n\n\n\n<p><strong>Step 2<\/strong>:<\/p>\n\n\n\n<p>Edit \/etc\/fail2ban\/fail2ban.conf<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\"><p>nano -w \/etc\/fail2ban\/fail2ban.conf<\/p><\/blockquote>\n\n\n\n<p>Your fail2ban.conf should look something like this (the commented lines have been removed)<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\"><p>[Definition]<br>loglevel = 3<br>logtarget = \/var\/log\/fail2ban.log<br>socket = \/tmp\/fail2ban.sock<\/p><\/blockquote>\n\n\n\n<p><strong>Step 3<\/strong>:<\/p>\n\n\n\n<p>Edit \/etc\/fail2ban\/jail.conf<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\"><p>nano -w \/etc\/fail2ban\/jail.conf<\/p><\/blockquote>\n\n\n\n<p>Your jail.conf should look something like this (again comments have been removed)<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\"><p>[DEFAULT]<br>ignoreip = 127.0.0.1<br>bantime = 18000<br>maxretry = 3<\/p><p>backend = polling<br>destemail = youremail@domain.com<br>action = iptables[name=%(__name__)s, port=%(port)s]<br>mail-whois-lines[name=%(__name__)s, dest=%(destemail)s, logpath=%(logpath)s]<\/p><\/blockquote>\n\n\n<p>[ssh]<\/p>\n\n\n\n<p>enabled = true<br>port = ssh<br>filter = sshd<br>logpath = \/var\/log\/auth.log<br>maxretry = 6<\/p>\n\n\n<p>[apache]<\/p>\n\n\n\n<p>enabled = false<br>port = http<br>filter = apache-auth<br>logpath = \/var\/log\/apache*\/*access.log<br>maxretry = 6<\/p>\n\n\n<p>[apache-noscript]<\/p>\n\n\n\n<p>enabled = false<br>port = http<br>filter = apache-noscript<br>logpath = \/var\/log\/apache*\/*error.log<br>maxretry = 6<\/p>\n\n\n<p>[vsftpd]<\/p>\n\n\n\n<p>enabled = false<br>port = ftp<br>filter = vsftpd<br>logpath = \/var\/log\/auth.log<br>maxretry = 6<\/p>\n\n\n<p>[proftpd]<\/p>\n\n\n\n<p>enabled = false<br>port = ftp<br>filter = proftpd<br>logpath = \/var\/log\/proftpd\/proftpd.log<br>maxretry = 6<\/p>\n\n\n<p>[wuftpd]<\/p>\n\n\n\n<p>enabled = false<br>port = ftp<br>filter = wuftpd<br>logpath = \/var\/log\/auth.log<br>maxretry = 6<\/p>\n\n\n<p>[postfix]<\/p>\n\n\n\n<p>enabled = false<br>port = smtp<br>filter = postfix<br>logpath = \/var\/log\/mail.log<\/p>\n\n\n<p>[couriersmtp]<\/p>\n\n\n\n<p>enabled = true<br>port = smtp<br>filter = couriersmtp<br>logpath = \/var\/log\/mail.log<\/p>\n\n\n<p>[courierimap]<\/p>\n\n\n\n<p>enabled = true<br>port = imap2<br>filter = courierlogin<br>failregex = imapd: LOGIN FAILED.*ip=[.*:]<br>logpath = \/var\/log\/mail.log<br>maxretry = 5<\/p>\n\n\n<p>[courierpop3]<\/p>\n\n\n\n<p>enabled = true<br>port = pop3<br>filter = courierlogin<br>failregex = courierpop3login: LOGIN FAILED.*ip=[.*:]<br>logpath = \/var\/log\/mail.log<br>maxretry = 5<\/p>\n\n\n<p>[sasl]<\/p>\n\n\n\n<p>enabled = true<br>port = smtp<br>filter = sasl<br>failregex = warning: [-._w]+[]: SASL (?:LOGIN|PLAIN|(?:CRAM|DIGEST)-MD5) authentication failed<br>logpath = \/var\/log\/mail.log<\/p>\n\n\n\n<p>Please change the email section if you are going to directly copy and paste this config. Right now, when someone attempts a bruteforce attack, fail2ban will firewall the ip address, and send an email to that email address with the whois information, and the log information from the attack.<\/p>\n\n\n\n<p>You can now start\/restart fail2ban, I recommend using a restart just in case fail2ban is already running.<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\"><p>\/etc\/init.d\/fail2ban restart<\/p><\/blockquote>\n\n\n\n<p>Please don&#8217;t use this as your only security measure. This is just one step you can take to protecting your servers.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>This howto is going to assume you have a working Debian or Debian based system currently running. It is also intended to [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[10,12],"tags":[20,22,25,30,43,47,48],"class_list":["post-660","post","type-post","status-publish","format-standard","hentry","category-linux","category-security","tag-bruteforce","tag-debian","tag-fail2ban","tag-linux","tag-security","tag-ssh","tag-telnet"],"_links":{"self":[{"href":"https:\/\/www.jasonmartin.info\/index.php\/wp-json\/wp\/v2\/posts\/660","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.jasonmartin.info\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.jasonmartin.info\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.jasonmartin.info\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.jasonmartin.info\/index.php\/wp-json\/wp\/v2\/comments?post=660"}],"version-history":[{"count":0,"href":"https:\/\/www.jasonmartin.info\/index.php\/wp-json\/wp\/v2\/posts\/660\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.jasonmartin.info\/index.php\/wp-json\/wp\/v2\/media?parent=660"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.jasonmartin.info\/index.php\/wp-json\/wp\/v2\/categories?post=660"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.jasonmartin.info\/index.php\/wp-json\/wp\/v2\/tags?post=660"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}