{"id":45,"date":"2014-11-01T20:18:00","date_gmt":"2014-11-01T20:18:00","guid":{"rendered":"https:\/\/www.tech-and-dev.com\/blog\/2014\/11\/01\/protecting-owncloud-against-bruteforce-attacks-with-fail2ban\/"},"modified":"2021-02-22T01:02:57","modified_gmt":"2021-02-22T01:02:57","slug":"protecting-owncloud-against-bruteforce-attacks-with-fail2ban","status":"publish","type":"post","link":"https:\/\/www.tech-and-dev.com\/blog\/2014\/11\/protecting-owncloud-against-bruteforce-attacks-with-fail2ban.html","title":{"rendered":"Protecting Owncloud Against Bruteforce Attacks With Fail2ban"},"content":{"rendered":"<div dir=\"ltr\" style=\"text-align: left;\">\n<div style=\"clear: both; text-align: center;\"><a style=\"margin-left: 1em; margin-right: 1em;\" href=\"https:\/\/www.tech-and-dev.com\/blog\/wp-content\/uploads\/2021\/02\/owncloud-logo.png\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.tech-and-dev.com\/blog\/wp-content\/uploads\/2021\/02\/owncloud-logo.png\" width=\"200\" height=\"200\" border=\"0\" \/><\/a><\/div>\n<div style=\"text-align: justify;\"><\/div>\n<div style=\"text-align: justify;\">OwnCloud is a great web application that can be installed on a server and allows the sync &amp; share of files, music, movies, calendar and contacts. However, one weakness that ownCloud users face is a brute force attack against the login page.<\/div>\n<div style=\"text-align: justify;\"><\/div>\n<div style=\"text-align: justify;\">Fail2Ban is a software that scan logs for malicious behaviors and update the firewall rules by banning IPs for a specified amount of time.<\/div>\n<p><a name=\"more\"><\/a><\/p>\n<h2 style=\"text-align: left;\">Requirements:<\/h2>\n<ol style=\"text-align: left;\">\n<li>OwnCloud 7.0.2 or higher installed<\/li>\n<li>Fail2Ban installed<\/li>\n<\/ol>\n<h2 style=\"text-align: left;\">1- Configuring Fail2Ban<\/h2>\n<p>Copy Fail2Ban configuration file, never use jail.conf, it will get overwritten when fail2ban is updated.<\/p>\n<blockquote><p>cp \/etc\/fail2ban\/jail.conf \/etc\/fail2ban\/jail.local<\/p><\/blockquote>\n<div style=\"text-align: left;\"><\/div>\n<h2 style=\"text-align: left;\">2- Open the configuration file:<\/h2>\n<blockquote><p>vi \/etc\/fail2ban\/jail.local<\/p><\/blockquote>\n<p>Append at the end of the file:<\/p>\n<blockquote><p>#OwnCloud<br \/>\n[owncloud]<br \/>\nenabled\u00a0 = true<br \/>\nfilter\u00a0\u00a0 = owncloud<br \/>\naction = iptables-multiport[name=owncloud, port=&#8221;http,https&#8221;]<br \/>\nlogpath\u00a0 = \/home\/yourusername\/public_html\/data\/owncloud.log<br \/>\nmaxretry = 5<\/p><\/blockquote>\n<p><b>enabled:<\/b> Should be set to true for fail2ban to ban the offending IPs.<br \/>\n<b>filter: <\/b>the filter filename, which will be created in the next step.<br \/>\n<b>action:<\/b> the action that will be taken when the maximum number of failed logins is reached. In this example, we&#8217;re blocking both the http and https port (port 80 and 443 by default).<br \/>\n<b>logpath:<\/b> the path to owncloud log file. As of ownCloud 7.0.2, the log file is automatically created in the data directory. If you&#8217;re using an older version of ownCloud that doesn&#8217;t create a logfile, you can create log file and add it to the logpath. For example:<br \/>\nvi \/var\/log\/owncloud.log<br \/>\nchown oc:oc owncloud.log<br \/>\n<b>maxretry:<\/b> the allowed number of failed login attempts before fail2ban bans the IP.<\/p>\n<p>&nbsp;<\/p>\n<h2 style=\"text-align: left;\">3- Create a filter for ownCloud and add the following inside it:<\/h2>\n<h3 style=\"text-align: left;\">For Owncloud 7<\/h3>\n<blockquote><p>vi \/etc\/fail2ban\/filter.d\/owncloud.conf<\/p><\/blockquote>\n<blockquote><p>[Definition]<br \/>\nfailregex={&#8220;app&#8221;:&#8221;core&#8221;,&#8221;message&#8221;:&#8221;Login failed: &#8216;.*&#8217; (Remote IP: &#8216;&lt;HOST&gt;&#8217;, X-Forwarded-For: &#8216;.*&#8217;)&#8221;,&#8221;level&#8221;:2,&#8221;time&#8221;:&#8221;.*&#8221;}<br \/>\nignoreregex =<\/p><\/blockquote>\n<h3 style=\"text-align: left;\">For Owncloud 8<\/h3>\n<blockquote><p>vi \/etc\/fail2ban\/filter.d\/owncloud.conf<\/p><\/blockquote>\n<blockquote><p>[Definition]<br \/>\nfailregex={&#8220;reqId&#8221;:&#8221;.*&#8221;,&#8221;remoteAddr&#8221;:&#8221;.*&#8221;,&#8221;app&#8221;:&#8221;core&#8221;,&#8221;message&#8221;:&#8221;Login failed: &#8216;.*&#8217; (Remote IP: &#8216;&lt;HOST&gt;&#8217;, X-Forwarded-For: &#8216;.*&#8217;)&#8221;,&#8221;level&#8221;:2,&#8221;time&#8221;:&#8221;.*&#8221;}<br \/>\nignoreregex =<\/p><\/blockquote>\n<p>&nbsp;<\/p>\n<h2 style=\"text-align: left;\">4- Setting ownCloud log file<\/h2>\n<p>Go to<b> ownCloud<\/b>, click on your <b>username <\/b>on top right, go to <b>Admin<\/b> section, scroll down to the <b>Log<\/b> section and choose: <b>warnings, errors and fatal issues<\/b>.<\/p>\n<div style=\"clear: both; text-align: center;\"><a style=\"margin-left: 1em; margin-right: 1em;\" href=\"https:\/\/www.tech-and-dev.com\/blog\/wp-content\/uploads\/2021\/02\/owncloud-log-type.png\"><img decoding=\"async\" src=\"https:\/\/www.tech-and-dev.com\/blog\/wp-content\/uploads\/2021\/02\/owncloud-log-type.png\" border=\"0\" \/><\/a><\/div>\n<p>&nbsp;<\/p>\n<h2 style=\"text-align: left;\">5- Restart fail2ban<\/h2>\n<blockquote><p>service fail2ban restart<\/p><\/blockquote>\n<p>Fail2ban should now ban all the IPs that are failing the login 5 times.<\/p>\n<p><b>Have Any Questions? Please let me know! <\/b><\/p>\n<p>&nbsp;<\/p>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>OwnCloud is a great web application that can be installed on a server and allows the sync &amp; share of files, music, movies, calendar and contacts. However, one weakness that ownCloud users face is a brute force attack against the login page. Fail2Ban is a software that scan logs for malicious behaviors and update the [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[23,25,6,7],"tags":[],"class_list":["post-45","post","type-post","status-publish","format-standard","hentry","category-brute-force","category-fail2ban","category-linux","category-ssh"],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/www.tech-and-dev.com\/blog\/wp-json\/wp\/v2\/posts\/45","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.tech-and-dev.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.tech-and-dev.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.tech-and-dev.com\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.tech-and-dev.com\/blog\/wp-json\/wp\/v2\/comments?post=45"}],"version-history":[{"count":2,"href":"https:\/\/www.tech-and-dev.com\/blog\/wp-json\/wp\/v2\/posts\/45\/revisions"}],"predecessor-version":[{"id":283,"href":"https:\/\/www.tech-and-dev.com\/blog\/wp-json\/wp\/v2\/posts\/45\/revisions\/283"}],"wp:attachment":[{"href":"https:\/\/www.tech-and-dev.com\/blog\/wp-json\/wp\/v2\/media?parent=45"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.tech-and-dev.com\/blog\/wp-json\/wp\/v2\/categories?post=45"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.tech-and-dev.com\/blog\/wp-json\/wp\/v2\/tags?post=45"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}