<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom"><title>Guguweb - joomla</title><link href="https://www.guguweb.com/" rel="alternate"></link><link href="https://www.guguweb.com/feeds/joomla.atom.xml" rel="self"></link><id>https://www.guguweb.com/</id><updated>2022-01-07T15:59:56+01:00</updated><subtitle>Freelance developer and sysadmin</subtitle><entry><title>How to protect your Joomla instance from brute force attacks with Fail2ban</title><link href="https://www.guguweb.com/2014/03/31/joomla-brute-force-attacks-file2ban/" rel="alternate"></link><published>2014-03-31T08:58:04+00:00</published><updated>2022-01-07T15:59:56+01:00</updated><author><name>Augusto Destrero</name></author><id>tag:www.guguweb.com,2014-03-31:/2014/03/31/joomla-brute-force-attacks-file2ban/</id><summary type="html">&lt;p&gt;If you administer at least one Joomla instance you&amp;#8217;ll be subject to brute force attacks before or after. &lt;a title="Fail2ban home page" href="http://www.fail2ban.org/wiki/index.php/Main_Page" target="_blank" rel="noopener noreferrer"&gt;Fail2ban&lt;/a&gt; is a very nice service written in Python which periodically scans your log files looking for signs of brute force attacks and perform some actions when an attack is discovered …&lt;/p&gt;</summary><content type="html">&lt;p&gt;If you administer at least one Joomla instance you&amp;#8217;ll be subject to brute force attacks before or after. &lt;a title="Fail2ban home page" href="http://www.fail2ban.org/wiki/index.php/Main_Page" target="_blank" rel="noopener noreferrer"&gt;Fail2ban&lt;/a&gt; is a very nice service written in Python which periodically scans your log files looking for signs of brute force attacks and perform some actions when an attack is discovered. The most common actions is to ban the attacker IP at firewall level and send an email to the server administrator.&lt;/p&gt;
&lt;p&gt;Fail2ban comes bundled with filters for many common services (ssh, apache authentication, etc.), but it lacks a built-in Joomla integration. Anyway it&amp;#8217;s easy to add a Joomla filter to Fail2ban, here I explain how to do it.&lt;/p&gt;
&lt;div class="toc"&gt;&lt;span class="toctitle"&gt;Table of Contents&lt;/span&gt;&lt;ul&gt;
&lt;li&gt;&lt;a href="#install-fail2ban"&gt;Install Fail2ban&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="#install-fail2ban-joomla-plugin"&gt;Install Fail2ban Joomla plugin&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="#fail2ban-configuration"&gt;Fail2ban configuration&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="#be-happy-when-an-attacker-gets-banned"&gt;Be happy when an attacker gets banned&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/div&gt;
&lt;h2 id="install-fail2ban"&gt;Install Fail2ban&lt;/h2&gt;
&lt;p&gt;Installing fail2ban in a Debian based server is as simple as issuing the following command:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;$ apt-get install fail2ban
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;Configuring Fail2ban properly is out of scope of this howto, you can find many resources online and in the official Fail2ban wiki.&lt;/p&gt;
&lt;h2 id="install-fail2ban-joomla-plugin"&gt;Install Fail2ban Joomla plugin&lt;/h2&gt;
&lt;p&gt;To ease the integration of Fail2ban with Joomla authentication system you can install a &lt;a title="Joomla file2ban plugin" href="http://extensions.joomla.org/extensions/extension?searchall=fail2ban&amp;filter%5Btags%5D%5B%5D=&amp;filter%5Bcore_catid%5D=&amp;filter%5Bincludes%5D=&amp;filter%5Bversions%5D=&amp;filter%5Btype%5D=&amp;filter%5Bhasdemo%5D=&amp;order=&amp;filter%5Bnewupdated%5D=&amp;filter%5Bscore%5D=&amp;filter%5Bfavourites%5D=&amp;dir=DESC&amp;limitstart=0&amp;controller=filter&amp;view=extension&amp;layout=list&amp;Itemid=145&amp;clearorders=0&amp;clearfilters=1" target="_blank" rel="noopener noreferrer"&gt;Joomla fail2ban plugin&lt;/a&gt; using the standard Joomla plugin installation mechanism. This plugin logs Joomla authentication errors in the standard web server error log. There it will be easy for Fail2ban to scan for errors and ban the attackers IPs.&lt;/p&gt;
&lt;p&gt;After installing and activating the plugin you&amp;#8217;ll find something like this in your web server error log when user authentication fails in Joomla:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="nf"&gt;var&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;apache2&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;mywebsite_error&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="err"&gt;:&lt;/span&gt;&lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="n"&gt;Mon Mar 31 10:13:58 2014&lt;/span&gt;&lt;span class="o"&gt;]&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="n"&gt;error&lt;/span&gt;&lt;span class="o"&gt;]&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="n"&gt;client 212.109.14.203&lt;/span&gt;&lt;span class="o"&gt;]&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="k"&gt;user&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;mywebsite&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;authentication&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;failure&lt;/span&gt;&lt;span class="w"&gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;h2 id="fail2ban-configuration"&gt;Fail2ban configuration&lt;/h2&gt;
&lt;p&gt;Save this Fail2ban filter in a file called joomla-error.conf and save it in /etc/fail2ban/filters.d:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;&lt;span class="k"&gt;[Definition]&lt;/span&gt;

&lt;span class="c1"&gt;# Option: failregex&lt;/span&gt;
&lt;span class="c1"&gt;# Notes.: matches something like:&lt;/span&gt;
&lt;span class="c1"&gt;# [Mon Mar 31 10:15:00 2014] [error] [client 212.109.14.203] user mywebsite authentication failure&lt;/span&gt;
&lt;span class="c1"&gt;# Values: TEXT&lt;/span&gt;
&lt;span class="na"&gt;failregex&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s"&gt;[[]client &amp;amp;amp;lt;HOST&amp;amp;amp;gt;[]] user .* authentication failure.*&lt;/span&gt;

&lt;span class="c1"&gt;# Option: ignoreregex&lt;/span&gt;
&lt;span class="c1"&gt;# Notes.: regex to ignore. If this regex matches, the line is ignored.&lt;/span&gt;
&lt;span class="c1"&gt;# Values: TEXT&lt;/span&gt;
&lt;span class="c1"&gt;#&lt;/span&gt;
&lt;span class="na"&gt;ignoreregex&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;Add this jail to your /etc/fail2ban/jail.local:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;&lt;span class="k"&gt;[joomla-error]&lt;/span&gt;
&lt;span class="na"&gt;enabled&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s"&gt;true&lt;/span&gt;
&lt;span class="na"&gt;port&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s"&gt;http,https&lt;/span&gt;
&lt;span class="na"&gt;filter&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s"&gt;joomla-error&lt;/span&gt;
&lt;span class="na"&gt;logpath&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s"&gt;/var/log/apache2/*error.log&lt;/span&gt;
&lt;span class="na"&gt;maxretry&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s"&gt;5&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;Reload fail2ban configuration with:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;&lt;span class="o"&gt;$&lt;/span&gt; &lt;span class="n"&gt;fail2ban&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;client&lt;/span&gt; &lt;span class="n"&gt;reload&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;h2 id="be-happy-when-an-attacker-gets-banned"&gt;Be happy when an attacker gets banned&lt;/h2&gt;
&lt;p&gt;If you configured Fail2ban to send you an email when an attacker is banned you&amp;#8217;ll receive an email with a text similar to the following:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;The IP 212.109.14.203 has just been banned by Fail2Ban after 5 attempts against joomla-error.
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;The attacker IP here is left on purpose. I think it&amp;#8217;s useful to expose attackers IP in public! 😉&lt;/p&gt;</content><category term="web"></category><category term="joomla"></category><category term="security"></category></entry></feed>