<?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>andymadge.com &#187; Security</title>
	<atom:link href="http://www.andymadge.com/category/security/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.andymadge.com</link>
	<description>Nothing to see here, move along…</description>
	<lastBuildDate>Sun, 23 Aug 2009 20:37:21 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=abc</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Password Salting Techniques</title>
		<link>http://www.andymadge.com/2009/08/password-salting-techniques/</link>
		<comments>http://www.andymadge.com/2009/08/password-salting-techniques/#comments</comments>
		<pubDate>Sun, 09 Aug 2009 18:36:52 +0000</pubDate>
		<dc:creator>AndyM</dc:creator>
				<category><![CDATA[Computers]]></category>
		<category><![CDATA[Security]]></category>
		<category><![CDATA[Web Development]]></category>

		<guid isPermaLink="false">http://www.andymadge.com/?p=163</guid>
		<description><![CDATA[This article is about using salting techniques to improve the security of authentication for websites.  Examples are in PHP but the techniques apply to any language.

Caveat
Before I continue, I just want to make an important point:
The single best piece of advice I can give when building your own authentication system is&#8230;

Don&#8217;t do it.

I don&#8217;t mean [...]]]></description>
			<content:encoded><![CDATA[<p>This article is about using salting techniques to improve the security of authentication for websites.  Examples are in PHP but the techniques apply to any language.<span id="more-163"></span></p>
<blockquote>
<h2>Caveat</h2>
<p>Before I continue, I just want to make an important point:</p>
<p>The single best piece of advice I can give when building your own authentication system is&#8230;</p>
<ul>
<li>Don&#8217;t do it.</li>
</ul>
<p>I don&#8217;t mean don&#8217;t use authentication, what I mean is that cryptographic techniques are complicated.  Actually they&#8217;re extremely complicated.  If you don&#8217;t have years of experience as a cryptographer, you&#8217;re going to make mistakes that will leave security holes.  Guaranteed.</p>
<p>The alternative is to use a well respected authentication framework such as:</p>
<ul>
<li><a href="http://www.openwall.com/phpass/">PHPass</a></li>
<li><a href="http://framework.zend.com/manual/en/zend.auth.html">Zend_Auth</a> (requires Zend Framework)</li>
<li><a href="http://codeigniter.com/wiki/Category:Libraries::Authentication/">CodeIgniter Authentication Libraries</a> (require CodeIgniter)</li>
</ul>
<p><a href="http://www.openwall.com/phpass/"></a>Frameworks such as this are developed by people who really do know what they are doing, and any security holes are generally quickly discovered and plugged.</p>
<p>I&#8217;m certainly no cryptographer, and this article is based on my current understanding.</p>
<p>That said, assuming you&#8217;re going ahead anyway, let&#8217;s get back to the article&#8230;</p></blockquote>
<h2>Attacks</h2>
<p>Lets look at the type of attacks we want to protect against.</p>
<h3>Dictionary</h3>
<p>This involves having a list of common passwords and trying every one in turn.  Most dictionaries would contain millions of possibilities starting with obvious stuff like &#8220;password&#8221;, &#8220;123456&#8243; and more obscure ones such as &#8220;pa$$wOrD&#8221; (<a href="http://en.wikipedia.org/wiki/Dictionary_attack">wikipedia entry</a>)</p>
<h3>Brute Force</h3>
<p>This involves trying every possible password and in theory will always work against any system.  The problem is that it takes a LONG time to do.  As computing speed improves, obviously the time taken reduces.  Since you can&#8217;t make brute force attacks impossible, what you want to achieve is to make them take an infeasibly long time &#8211; like years. (<a href="http://en.wikipedia.org/wiki/Brute_force_attack">wikipedia entry</a>)</p>
<h3>Rainbow Tables</h3>
<p>This is a way of attacking hashed passwords.  The idea is that instead of calculating the hash of each password you want to try, you use a list of pre-calculated hashes, thus saving computation time. (<a href="http://en.wikipedia.org/wiki/Rainbow_table">wikipedia entry</a>)</p>
<p>Bearing those in mind, let&#8217;s look at the different ways you could store the password in your database:</p>
<h2 style="font-size: 1.5em;">Plain Text</h2>
<p>This is a massively bad idea.  If someone gets hold of your database, they know everybody&#8217;s password.</p>
<p>NEVER EVER STORE PASSWORDS AS PLAIN TEXT.  ANYWHERE.  EVER.</p>
<p>One argument against this is &#8220;The spec requires that the password be stored in case someone forgets it.&#8221;  If that&#8217;s the case, then you should use reversible encryption and DON&#8217;T STORE THE ENCRYPTION KEY IN THE DATABASE.</p>
<h2>Hashed Passwords</h2>
<p>A hash is a one-way algorithm that is commonly used in cryptography.  The idea is that there is no way to work backward to find out the password from the hash value.  There are many different hash algorithms, each with their own strengths and weaknesses. (<a href="http://uk3.php.net/manual/en/function.hash-algos.php">list of hash algorithms supported by PHP</a>)</p>
<p>The most commonly used hash functions are MD5 and SHA1:</p>
<pre style="padding-left: 30px; ">$password_hash = MD5( $password );</pre>
<p>Lots of people will tell you that MD5 is sufficient for most uses, others will say that SHA1 is more secure so you should use that instead.</p>
<p>While these are two of the least-secure hashing algorithms, they are still secure enough for any normal website (i.e. not a bank etc.)</p>
<p>Other more secure hash algorithms are SHA256 or Whirlpool, but these have the disadvantage of taking longer to calculate.</p>
<p>So at this point, we&#8217;re recommending:</p>
<pre style="font: normal normal normal 12px/18px Consolas, Monaco, 'Courier New', Courier, monospace; padding-left: 30px;">$password_hash = SHA1( $password );</pre>
<h3>Vulnerabilities</h3>
<p>Hashed passwords will provide complete protection against dictionary attacks.  They also protect effectively against brute force attacks since the operation would take an infeasibly long time, however they are still vulnerable to rainbow table attacks.</p>
<h2>Salting</h2>
<p><span style="font-weight: normal; font-size: 13px; ">Salting is a technique used to protect hashes against rainbow table attacks.  The idea is that an additional string &#8211; known as &#8217;salt&#8217; &#8211; is introduced into the hash value:</span></p>
<pre style="padding-left: 30px; ">$salt = "abcd";
$password_hash = SHA1( $salt . $password );</pre>
<p>So, if a rainbow table attack is successful, the attacker now still doesn&#8217;t know the password, they know <code>$salt.$password</code>.  In this trivial example, the attacker would soon work out what the salt was &#8211; especially if they break another account &#8211; and then they would know the password.</p>
<p>Let&#8217;s improve the salt&#8230;</p>
<pre style="font: normal normal normal 12px/18px Consolas, Monaco, 'Courier New', Courier, monospace; padding-left: 30px;">$salt = "<span style="font-family: 'courier new';">ZvmLcZMXw3WIA78uudt9SFysSGocIF</span>";
$password_hash = SHA1( $salt . $password );</pre>
<p>Here we are using a random static string as the salt, which is definitely an improvement, but since the salt is static (i.e. the same for every user) then they still only need to work it out once.  After that, every user&#8217;s account it vulnerable to the same attack.</p>
<p>Note that we could also hash the salt as follows:</p>
<pre style="font: normal normal normal 12px/18px Consolas, Monaco, 'Courier New', Courier, monospace; padding-left: 30px;">$salt = SHA1( "<span style="font-family: 'courier new';">ZvmLcZMXw3WIA78uudt9SFysSGocIF</span>" );</pre>
<p>However, all this does is increase the computation time without significantly increasing the security.  The attacker only needs to find the value of <code>$salt</code> &#8211; it&#8217;s completely irrelevant how it&#8217;s calculated.</p>
<p>We need to make the salt different for each user.  One way is to use something that will be different for each user.  The most obvious thing is the username (or maybe email):</p>
<pre style="font: normal normal normal 12px/18px Consolas, Monaco, 'Courier New', Courier, monospace; padding-left: 30px;">$password_hash = SHA1( $username . $password );</pre>
<p>This means that if two people have the same password, they will still have different password hashes.  If an attacker is successful with a rainbow table attack for one account, they know nothing about any of the other accounts on the system.</p>
<p>Better still, lets use a different randomly generated string as the salt for each user.  NOTE: In this case we&#8217;re going to need to store the salt alongside the user in the database otherwise we have no way of checking it.</p>
<pre style="font: normal normal normal 12px/18px Consolas, Monaco, 'Courier New', Courier, monospace; padding-left: 30px;">$salt = random_string();
$password_hash = SHA1( $salt . $password );</pre>
<p><code>random_string</code> is a function defined elsewhere in your code.  There are good examples <a href="http://stackoverflow.com/questions/48124/generating-pseudorandom-alpha-numeric-strings">here</a> and <a href="http://911-need-code-help.blogspot.com/2009/06/generate-random-strings-using-php.html">here</a>.</p>
<p>Finally, let&#8217;s combine some of the above into our best-yet version:</p>
<pre style="font: normal normal normal 12px/18px Consolas, Monaco, 'Courier New', Courier, monospace; padding-left: 30px;">$salt = random_string();
$password_hash = SHA1( $salt . MD5($email) . $password );</pre>
<p>I know I said above that there&#8217;s no point in hashing twice, but in this case it does have an effect &#8211; we don&#8217;t want the salting algorithm to be obvious and now password hash doesn&#8217;t contain anything that is recognizable as a word or email address.</p>
<p>It is important thing is that an attacker doesn&#8217;t know exactly how you have introduced the salt.  As a result you need to be careful with Open Source software, since the salting algorithm will be plainly visible in the source code &#8211; although this is mitigated if the salt contains a random string.</p>
<p>There are many different approaches to salting &#8211; this is just one fairly simple version.  For anything that requires a higher level of security, you&#8217;ll need to look at additional techniques.</p>
<p>As I mentioned above, I&#8217;m no security expert and I may have missed something.  If you think so, please let me know in the comment.</p>
<h2>Also&#8230;</h2>
<p>This hasn&#8217;t been the focus of the article but it&#8217;s relevant &#8211; whenever someone creates an account, changes their password or logs in, you&#8217;re going to be sending their password over the internet.  Unless you&#8217;re using HTTPS/SSL, then the password will be sent IN THE CLEAR i.e. as plain text.</p>
<p>Anyone who is listening in with a packet sniffer will be able to see the password so all of your back-end security goes out the window.</p>
<p>You may think &#8220;OK, so I&#8217;ll hash the password at the client using JavaScript before I send it.&#8221;   This actually doesn&#8217;t help at all &#8211; the attacker doesn&#8217;t know the password, but he does know the hash, so he can use a replay attack which in most cases is good enough for their needs.</p>
<p>You can improve the security by using <a href="http://en.wikipedia.org/wiki/Challenge_response">Challenge-Response</a> but the best alternative is to use SSL.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.andymadge.com/2009/08/password-salting-techniques/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Maintaining Privacy at an Internet Cafe</title>
		<link>http://www.andymadge.com/2006/09/maintaining-privacy-at-an-internet-cafe/</link>
		<comments>http://www.andymadge.com/2006/09/maintaining-privacy-at-an-internet-cafe/#comments</comments>
		<pubDate>Mon, 11 Sep 2006 16:28:45 +0000</pubDate>
		<dc:creator>AndyM</dc:creator>
				<category><![CDATA[Computers]]></category>
		<category><![CDATA[Security]]></category>
		<category><![CDATA[Useful Links]]></category>

		<guid isPermaLink="false">http://blog.andymadge.com/pc-help/2006/09/11/maintaining-privacy-at-an-internet-cafe/</guid>
		<description><![CDATA[Accessing any protected system from an Internet Cafe-type situation is always a risk.  This is because you have no way of knowing whether there is any spy/sniffing/keylogging software on the PC &#8211; either installed by another user or by the sysadmin.  The following are tips to minimise the risks

(Originally from here)
If you cannot [...]]]></description>
			<content:encoded><![CDATA[<p>Accessing any protected system from an Internet Cafe-type situation is always a risk.  This is because you have no way of knowing whether there is any spy/sniffing/keylogging software on the PC &#8211; either installed by another user or by the sysadmin.  The following are tips to minimise the risks</p>
<p><span id="more-22"></span></p>
<p>(Originally from <a href="http://www.experts-exchange.com/Security/Win_Security/Q_21496483.html">here</a>)</p>
<blockquote><p>If you cannot trust the network you are using when you are in an Internet Cafe then you should not use it for sensitive issues.</p>
<p>When using email you can use an encrypted service such as <a rel="nofollow" target="_blank" onclick="return openNew(this.href);" href="http://www.hushmail.com/">http://www.hushmail.com/</a></p>
<p>However, a system with a keylogger installed will obviously bypass the encryption of data.</p>
<p>The only way I can think you could protect against software such as a keylogger installed on the PC you are using is to perform an online spyware scan using one of the following:</p>
<p><a rel="nofollow" target="_blank" onclick="return openNew(this.href);" href="http://www.webroot.com/services/spyaudit_03.htm">http://www.webroot.com/services/spyaudit_03.htm</a></p>
<p><a rel="nofollow" target="_blank" onclick="return openNew(this.href);" href="http://www.pctools.com/spyware-doctor">http://www.pctools.com/spyware-doctor</a></p>
<p><a rel="nofollow" target="_blank" onclick="return openNew(this.href);" href="http://download.zonelabs.com/bin/promotions/spywaredetector/index3.html" class="broken_link" >http://download.zonelabs.com/bin/promotions/spywaredetector/index3.html</a></p></blockquote>
<blockquote><p>In addition to a spyware scan you can also perform virus / trojan scans in the same way using a service like <a rel="nofollow" target="_blank" onclick="return openNew(this.href);" href="http://housecall.antivirus.com/housecall/start_frame.asp">http://housecall.antivirus.com/housecall/start_frame.asp</a></p>
<p>If you are familiar with the version of Windows (and the normal running processes) the Cafe uses and can access the task manager to establish if they are any suspect running procceses.</p></blockquote>
<blockquote><p>Also, the visual keyboard on windows does nothing but slow you down, a software keylogger will pick this up (if it&#8217;s any good), but a hardware would likely not.</p></blockquote>
]]></content:encoded>
			<wfw:commentRss>http://www.andymadge.com/2006/09/maintaining-privacy-at-an-internet-cafe/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>10 Windows Password Myths</title>
		<link>http://www.andymadge.com/2006/08/10-windows-password-myths/</link>
		<comments>http://www.andymadge.com/2006/08/10-windows-password-myths/#comments</comments>
		<pubDate>Wed, 23 Aug 2006 10:57:04 +0000</pubDate>
		<dc:creator>AndyM</dc:creator>
				<category><![CDATA[Computers]]></category>
		<category><![CDATA[Security]]></category>

		<guid isPermaLink="false">http://blog.andymadge.com/uncategorized/2006/08/23/10-windows-password-myths/</guid>
		<description><![CDATA[Tips on choosing a Windows password and myths about what constitutes a good password here
]]></description>
			<content:encoded><![CDATA[<p>Tips on choosing a Windows password and myths about what constitutes a good password <a href="http://www.securityfocus.com/infocus/1554">here</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.andymadge.com/2006/08/10-windows-password-myths/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
