<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom"><title>Guguweb - security</title><link href="https://www.guguweb.com/" rel="alternate"></link><link href="https://www.guguweb.com/feeds/security.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>Configure SFTP access to your Ubuntu server through SSH</title><link href="https://www.guguweb.com/2015/12/07/configure-sftp-access-to-your-ubuntu-server-through-ssh/" rel="alternate"></link><published>2015-12-07T15:22:46+00:00</published><updated>2022-01-07T15:57:47+01:00</updated><author><name>Augusto Destrero</name></author><id>tag:www.guguweb.com,2015-12-07:/2015/12/07/configure-sftp-access-to-your-ubuntu-server-through-ssh/</id><summary type="html">&lt;hr&gt;
&lt;p&gt;Sometimes you have to give your users a way to manage files on your server. A typical scenario is a web server where your users manage their websites by themselves.&lt;/p&gt;
&lt;p&gt;The classical approach in this scenario was to use FTP to give file management capabilities to your users, but it …&lt;/p&gt;</summary><content type="html">&lt;hr&gt;
&lt;p&gt;Sometimes you have to give your users a way to manage files on your server. A typical scenario is a web server where your users manage their websites by themselves.&lt;/p&gt;
&lt;p&gt;The classical approach in this scenario was to use FTP to give file management capabilities to your users, but it has many drawbacks:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;You have to provision and maintain a new service on your server;&lt;/li&gt;
&lt;li&gt;FTP is an &lt;a href="http://slacksite.com/other/ftp.html" target="_blank" rel="noopener noreferrer"&gt;annoying protocol&lt;/a&gt; from a firewall configuration point of view;&lt;/li&gt;
&lt;li&gt;FTP is not encrypted by default, and you have to put some effort to configure an FTP server which is protected from sniffing.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;If you are a lazy sysadmin like me you&amp;#8217;ll prefer to use a service you already have, which is encrypted by default and do not require a special firewall configuration other than the port 22 you are already using.&lt;/p&gt;
&lt;p&gt;ssh to the rescue!&lt;/p&gt;
&lt;h2 id="configure-ssh-server-to-serve-a-directory-using-sftp-chrooting-the-user-on-that-directory"&gt;Configure ssh server to serve a directory using SFTP, chrooting the user on that directory&lt;/h2&gt;
&lt;p&gt;Edit the file /etc/ssh/sshd_config by adding the following lines at the bottom:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;Match group sftp
ChrootDirectory %h
X11Forwarding no
AllowTcpForwarding no
ForceCommand internal-sftp
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;In this way every user belonging to group &lt;em&gt;sftp&lt;/em&gt; will be chrooted in his home directory when connecting trough sftp.&lt;/p&gt;
&lt;p&gt;If you want to let users access using password, then add this configuration:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;PasswordAuthentication yes
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;Restart ssh server:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;sudo service ssh restart
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;Now add a new group called &lt;em&gt;sftp&lt;/em&gt;:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;sudo addgroup sftp
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;And add a system user that will be used to connect:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;sudo adduser --home /home/example.com/ --no-create-home --shell /usr/sbin/nologin username
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;Note how we set the home directory of the user to the root of the website, and how we set the shell to &lt;em&gt;nologin&lt;/em&gt; executable, in order to deny access from a regular ssh shell.&lt;/p&gt;
&lt;p&gt;Now add the user to &lt;em&gt;sftp&lt;/em&gt; group:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;sudo adduser username sftp
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;Set permissions correctly on username home directory and its content. The home directory itself should be owned by root and have 755 permissions, otherwise sftp login will fail:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;cd /home/example.com
chown root:sftp .
chmod 755 .
chown -R username:sftp *
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;Try to connect to your server on port 22 with a client supporting SFTP (such as &lt;a href="https://filezilla-project.org/" target="_blank" rel="noopener noreferrer"&gt;Filezilla&lt;/a&gt;). You should see the content of &lt;em&gt;/home/example.com&lt;/em&gt; directory, and you should not be able to go out from that directory.&lt;/p&gt;</content><category term="sysadmin"></category><category term="security"></category><category term="sftp"></category><category term="ssh"></category></entry><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>