<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>UNIXy &#187; EncFS</title>
	<atom:link href="http://blog.unixy.net/tag/encfs/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.unixy.net</link>
	<description>Fully Managed Dedicated Servers</description>
	<lastBuildDate>Fri, 03 Feb 2012 17:37:12 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3</generator>
		<item>
		<title>Protect Your Backup Files And Production Server From Intruders!</title>
		<link>http://blog.unixy.net/2009/03/protect-your-backup-files-and-production-server-from-intruders/</link>
		<comments>http://blog.unixy.net/2009/03/protect-your-backup-files-and-production-server-from-intruders/#comments</comments>
		<pubDate>Fri, 27 Mar 2009 05:06:44 +0000</pubDate>
		<dc:creator>UNIXy</dc:creator>
				<category><![CDATA[Security]]></category>
		<category><![CDATA[backup]]></category>
		<category><![CDATA[cPanel]]></category>
		<category><![CDATA[cpbackup]]></category>
		<category><![CDATA[DR]]></category>
		<category><![CDATA[EncFS]]></category>
		<category><![CDATA[WHM]]></category>
		<category><![CDATA[WHT]]></category>

		<guid isPermaLink="false">http://blog.unixy.net/?p=6</guid>
		<description><![CDATA[In this short post, I would like to share a technique that will protect your confidential data even if your backup store were to be compromised. We shall leverage the powerful open source Encryption Filesystem. I&#8217;ll go through all steps required to install the software, use it, and finally integrate it with your back up [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fblog.unixy.net%2F2009%2F03%2Fprotect-your-backup-files-and-production-server-from-intruders%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fblog.unixy.net%2F2009%2F03%2Fprotect-your-backup-files-and-production-server-from-intruders%2F&amp;style=normal&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
<p>In this short post, I would like to share a technique that will protect your confidential data even if your backup store were to be compromised. We shall leverage the powerful open source Encryption Filesystem. I&#8217;ll go through all steps required to install the software, use it, and finally integrate it with your back up strategy. This is a one-time configuration that doesn&#8217;t require much maintenance to keep it going and is well worth it in my opinion.</p>
<p>Off-server or off-network backup procedures are essential to any disaster recovery strategy. Current trends, however, show that little effort is directed at securing the backup node(s) and / or strategy. By storing plain text copies of your confidential databases, accounts, emails, and passwords on remote systems you&#8217;re exposing yourself to a host of issues. In light of the incident that affected WHT, if a capable intruder were to compromise your backup store (VPS, FTP, NFS, or server), it won&#8217;t take long before the intruder gains access to your production system. The consequences are material and the loss of productivity and revenue can break a business.</p>
<p><strong><span style="text-decoration: underline;">Installing EncFS</span></strong></p>
<p>While I&#8217;m only covering installation of EncFS on Debian and Redhat derivatives, it&#8217;s relatively easy to install it on other Linux distributions. Special instructions are required to install the tools on OpenVZ. See <a href="http://wiki.openvz.org/FUSE" target="_blank">http://wiki.openvz.org/FUSE</a></p>
<p><strong>ON DEBIAN DISTRIBUTIONS</strong></p>
<p>Let&#8217;s install EncFS and libraries. As root inside the shell prompt, execute the following two commands:</p>
<div style="margin: 5px 20px 20px;">
<table border="0" cellspacing="0" cellpadding="6" width="100%">
<tbody>
<tr>
<td class="alt2" style="border: 1px inset;"># apt-get install encfs libfuse2<br />
# modprobe fuse</td>
</tr>
</tbody>
</table>
</div>
<p><strong>ON REDHAT DISTRIBUTIONS</strong></p>
<p>First you have to add a yum application repository. Create a file called rpmforge.repo under /etc/yum.repos.d/rpmforge.repo and, with a text editor, copy / paste the following in it (this is for centos 5 / redhat 5. Checkout DAG for other versions):</p>
<div style="margin: 5px 20px 20px;">
<table border="0" cellspacing="0" cellpadding="6" width="100%">
<tbody>
<tr>
<td class="alt2" style="border: 1px inset;"># Name: RPMforge RPM Repository for Red Hat Enterprise 5 &#8211; dag<br />
# URL: <a href="http://rpmforge.net/" target="_blank">http://rpmforge.net/</a><br />
[rpmforge]<br />
name = Red Hat Enterprise $releasever &#8211; RPMforge.net &#8211; dag<br />
#baseurl = http://apt.sw.be/redhat/el5/en/$basearch/dag<br />
mirrorlist = <a href="http://apt.sw.be/redhat/el5/en/mirrors-rpmforge" target="_blank">http://apt.sw.be/redhat/el5/en/mirrors-rpmforge</a><br />
#mirrorlist = file:///etc/yum.repos.d/mirrors-rpmforge<br />
enabled = 1<br />
protect = 0<br />
gpgkey = file:///etc/pki/rpm-gpg/RPM-GPG-KEY-rpmforge-dag<br />
gpgcheck = 1</td>
</tr>
</tbody>
</table>
</div>
<p>Save and exit. Then run the following commands as root:</p>
<div style="margin: 5px 20px 20px;">
<table border="0" cellspacing="0" cellpadding="6" width="100%">
<tbody>
<tr>
<td class="alt2" style="border: 1px inset;"># yum install fuse-encfs dkms-fuse<br />
# modprobe fuse</td>
</tr>
</tbody>
</table>
</div>
<p><strong><span style="text-decoration: underline;">Using EncFS</span></strong></p>
<p>EncFS is a set of tools that allow the creation of a filesystem that is by default encrypted. The encrypted filesystem can be mounted similarly to a hard drive. With EncFS, however, the encrypted filesystem is protected by a password. And this is where it&#8217;s useful. When you transfer your backup files from your production server to an off-server backup store, you&#8217;re transferring and storing clear text files and information. So, how do we use these tools to secure our backup store?</p>
<p>In brief, here are the steps we&#8217;re setting to accomplish</p>
<p><strong>A)</strong> Initialize a folder on the production server as an EncFS volume and mount it<br />
<strong>B)</strong> Point our backup scripts to the encrypted volume to store the generated backups<br />
<strong>C)</strong> Seal the encrypted volume<br />
<strong>D)</strong> Finally, transfer the encrypted files over to the backup store</p>
<p><strong>A)</strong> First of all, we need to initialize the backup filesystem. Here&#8217;s are the steps:</p>
<div style="margin: 5px 20px 20px;">
<table border="0" cellspacing="0" cellpadding="6" width="100%">
<tbody>
<tr>
<td class="alt2" style="border: 1px inset;"># <strong>mkdir /encrypted /decrypted</strong><br />
# <strong>encfs /encrypted/ /decrypted/</strong><br />
Creating new encrypted volume.<br />
Please choose from one of the following options:<br />
enter &#8220;x&#8221; for expert configuration mode,<br />
enter &#8220;p&#8221; for pre-configured paranoia mode,<br />
anything else, or an empty line will select standard mode.<br />
?&gt; <strong>&lt;HIT ENTER&gt;</strong></p>
<p>Standard configuration selected.</p>
<p>Configuration finished.  The filesystem to be created has<br />
the following properties:<br />
Filesystem cipher: &#8220;ssl/blowfish&#8221;, version 2:1:1<br />
Filename encoding: &#8220;nameio/block&#8221;, version 3:0:1<br />
Key Size: 160 bits<br />
Block Size: 512 bytes<br />
Each file contains 8 byte header with unique IV data.<br />
Filenames encoded using IV chaining mode.</p>
<p>Now you will need to enter a password for your filesystem.<br />
You will need to remember this password, as there is absolutely<br />
no recovery mechanism.  However, the password can be changed<br />
later using encfsctl.</p>
<p>New Encfs Password: <strong>&lt;PASSWORD&gt;</strong><br />
Verify Encfs Password: <strong>&lt;PASSWORD&gt;</strong></td>
</tr>
</tbody>
</table>
</div>
<p>At this point in the steps, we have created an encrypted and a decrypted folder. Plain text backups should always be copied in the /decrypted folder. Once copied, we unmounted the decrypted folder and leave all as is. Make sure you remember the Encfs password as it&#8217;s the only way to decrypt your backup files.</p>
<p>As a quick demo, let&#8217;s copy a random file in /decrypted to see all of this in action</p>
<p>Let&#8217;s pick a random file</p>
<div style="margin: 5px 20px 20px;">
<table border="0" cellspacing="0" cellpadding="6" width="100%">
<tbody>
<tr>
<td class="alt2" style="border: 1px inset;"># du -sh /tmp/unixy.zip<br />
2.9M	/tmp/unixy.zip</td>
</tr>
</tbody>
</table>
</div>
<p>Mount the encrypted filesystem:</p>
<div style="margin: 5px 20px 20px;">
<table border="0" cellspacing="0" cellpadding="6" width="100%">
<tbody>
<tr>
<td class="alt2" style="border: 1px inset;"># encfs /encrypted/ /decrypted/# cp /tmp/unixy.zip /decrypted/</p>
<p># ls -al /decrypted/<br />
total 2948<br />
drwxr-xr-x  2 root root    4096 2009-03-26 13:49 .<br />
drwxr-xr-x 23 root root    4096 2009-03-26 12:39 ..<br />
-rw&#8212;&#8212;-  1 root root 3006176 2009-03-26 13:49 unixy.zip</p>
<p># ls -al /encrypted/<br />
total 2952<br />
drwxr-xr-x  2 root root    4096 2009-03-26 13:49 .<br />
drwxr-xr-x 23 root root    4096 2009-03-26 12:39 ..<br />
-rw-r&#8212;&#8211;  1 root root     224 2009-03-26 12:40 .encfs5<br />
-rw&#8212;&#8212;-  1 root root 3006184 2009-03-26 13:49 HMDEZvfTz7HQnO5tyOsgAiIl</td>
</tr>
</tbody>
</table>
</div>
<p><strong>B)</strong> If you have custom backup scripts, all you have to do in this step is the following</p>
<p>1) Before we modify the backup scripts, we need to store the encryption password in a file under the folder /root. Call it file /root/enc.txt and on the first line type in the password after running the below<em> chmod</em> command.</p>
<div style="margin: 5px 20px 20px;">
<table border="0" cellspacing="0" cellpadding="6" width="100%">
<tbody>
<tr>
<td class="alt2" style="border: 1px inset;"># touch /root/enc.txt<br />
# chmod 700 /root/enc.txt # The file shouldn&#8217;t be readable to anyone other than user root</td>
</tr>
</tbody>
</table>
</div>
<p>Add this command at the top of the backup script:</p>
<div style="margin: 5px 20px 20px;">
<table border="0" cellspacing="0" cellpadding="6" width="100%">
<tbody>
<tr>
<td class="alt2" style="border: 1px inset;"># cat /root/enc.txt | encfs -S /encrypted /decrypted</td>
</tr>
</tbody>
</table>
</div>
<p>What this does is &#8220;feed&#8221; the encryption password to the command &#8220;encfs&#8221; so it runs unattended. Otherwise, encfs is interactive and might hand waiting for you to enter the password. Remember, we want to set this up and let it run itself.</p>
<p>Add this command at the end of the backup script:</p>
<div style="margin: 5px 20px 20px;">
<table border="0" cellspacing="0" cellpadding="6" width="100%">
<tbody>
<tr>
<td class="alt2" style="border: 1px inset;"># fusermount -u /decrypted</td>
</tr>
</tbody>
</table>
</div>
<p>For cPanel users, you can put include the above two steps in script files called /scripts/precpbackup and /scripts/postcpbackup as such:</p>
<p>Inside file /scripts/precpbackup</p>
<div style="margin: 5px 20px 20px;">
<table border="0" cellspacing="0" cellpadding="6" width="100%">
<tbody>
<tr>
<td class="alt2" style="border: 1px inset;">#!/bin/bashexport PATH=$PATH:/usr/bin:/usr/sbin:/sbin</p>
<p>cat /root/enc.txt | encfs -S /encrypted /decrypted</td>
</tr>
</tbody>
</table>
</div>
<p># In file /scripts/postcpbackup</p>
<div style="margin: 5px 20px 20px;">
<table border="0" cellspacing="0" cellpadding="6" width="100%">
<tbody>
<tr>
<td class="alt2" style="border: 1px inset;">#!/bin/bashexport PATH=$PATH:/usr/bin:/usr/sbin:/sbin</p>
<p>fusermount -u /decrypted</td>
</tr>
</tbody>
</table>
</div>
<p>Finally, make sure the two scripts are executable:</p>
<div style="margin: 5px 20px 20px;">
<table border="0" cellspacing="0" cellpadding="6" width="100%">
<tbody>
<tr>
<td class="alt2" style="border: 1px inset;"># chmod +x /scripts/*cpbackup</td>
</tr>
</tbody>
</table>
</div>
<p>From WHM, in backup configuration, put /decrypted as the backup folder. And we&#8217;re done!</p>
<p><strong>C)</strong> Let&#8217;s unmount the unencrypted filesystem since we&#8217;re done copying our files.</p>
<div style="margin: 5px 20px 20px;">
<table border="0" cellspacing="0" cellpadding="6" width="100%">
<tbody>
<tr>
<td class="alt2" style="border: 1px inset;"># fusermount -u /decrypted/<br />
# ls -al /decrypted/<br />
total 8<br />
drwxr-xr-x  2 root root 4096 2009-03-26 12:39 .<br />
drwxr-xr-x 23 root root 4096 2009-03-26 12:39 ..<br />
# ls -al /encrypted/<br />
total 2952<br />
drwxr-xr-x  2 root root    4096 2009-03-26 13:49 .<br />
drwxr-xr-x 23 root root    4096 2009-03-26 12:39 ..<br />
-rw-r&#8212;&#8211;  1 root root     224 2009-03-26 12:40 .encfs5<br />
-rw&#8212;&#8212;-  1 root root 3006184 2009-03-26 13:49 HMDEZvfTz7HQnO5tyOsgAiIl</p>
<p># ls -al encrypted/HMDEZvfTz7HQnO5tyOsgAiIl<br />
-rw&#8212;&#8212;- 1 root root 3006184 2009-03-26 13:49 encrypted/HMDEZvfTz7HQnO5tyOsgAiIl</td>
</tr>
</tbody>
</table>
</div>
<p>Sweet!</p>
<p><strong>D)</strong> Transfer the encrypted backup files to the destination backup store</p>
<p>Now your backup files are secure. You can simply SCP or rsync the encrypted files from the encrypted FS /encrypted. <span style="color: #ff0000;"><strong>Make sure to copy the .encfs5 file located inside the /encrypted directory. Without this file, the encrypted file are NOT recoverable!</strong></span></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.unixy.net/2009/03/protect-your-backup-files-and-production-server-from-intruders/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

