<?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>insanesecurity &#187; Encryption</title>
	<atom:link href="http://insanesecurity.info/blog/tag/encryption/feed" rel="self" type="application/rss+xml" />
	<link>http://insanesecurity.info/blog</link>
	<description>security through a distorted eye</description>
	<lastBuildDate>Thu, 25 Feb 2010 22:31:12 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>8 Tips For A Secure Login Script/Admin Panel</title>
		<link>http://insanesecurity.info/blog/8-tips-for-a-secure-login-scriptadmin-panel</link>
		<comments>http://insanesecurity.info/blog/8-tips-for-a-secure-login-scriptadmin-panel#comments</comments>
		<pubDate>Wed, 24 Jun 2009 16:53:57 +0000</pubDate>
		<dc:creator>dblackshell</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[How To]]></category>
		<category><![CDATA[CAPTCHA]]></category>
		<category><![CDATA[Encryption]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://insanesecurity.info/blog/?p=76</guid>
		<description><![CDATA[After reading the title you may say to yourself &#8220;Oh no, another &#60;&#60;secure login script&#62;&#62; article! Aren&#8217;t there enough already online?&#8221;. Yes there are, but unfortunately many tutorials (if it&#8217;s appropriate to call them so) only show you how to write SQL Injection free code. But that isn&#8217;t enough. What about brute force (dictionary, hybrid) [...]]]></description>
			<content:encoded><![CDATA[<p>After reading the title you may say to yourself &#8220;Oh no, another &lt;&lt;secure login script&gt;&gt; article! Aren&#8217;t there enough already online?&#8221;. Yes there are, but unfortunately many tutorials (if it&#8217;s appropriate to call them so) only show you how to write SQL Injection free code. But that isn&#8217;t enough. What about brute force (dictionary, hybrid) attacks? Or how about making your admin panel (user panel) CSRF free? Well this article will try to deal with those issues too.</p>
<p><span id="more-76"></span></p>
<h2>Tip 1: Login Page/Authentication</h2>
<p>Let&#8217;s start with the basic example, which you can find in all those so similar tutorials&#8230; First of is the login form:</p>
<pre>
&lt;form action="login.php" method="post"&gt;
    &lt;input type="text" name="username" /&gt;
    &lt;input type="password" name="password" /&gt;

    &lt;input type="submit" name="Login" /&gt;
&lt;/form>
</pre>
<p>Very complex html code, I know. It took me around 10 minutes to write it. Now for the php script that does all the work. <strong>NOTE</strong>: In this example and all to follow we always assume a mysql connection has been made and that sessions are started.</p>
<pre>
$username = mysql_real_escape_string($_POST['username']);
$password = sha1('salt'.$_POST['password']);
$result = mysql_query(
    "SELECT id
     FROM users
     WHERE username='$username' AND password='$password'
     ORDER BY id"
);
if(1!=mysql_num_rows($result)) {
    echo 'Login failed, username or password was wrong!';
    exit;
}
$_SESSION['auth'] = true;
$_SESSION['username'] = $username;
$_SESSION['id'] = mysql_result($result, 0);
echo 'Logged in!';
</pre>
<p>If everything is clear till now than we can move onward&#8230; (with this first section I&#8217;ve done a summary of all the secure login scripts tutorials)</p>
<p><script type="text/javascript"><!--
google_ad_client = "pub-4879499347590889";
/* 468x60, created 1/22/09 */
google_ad_slot = "0361207255";
google_ad_width = 468;
google_ad_height = 60;
//-->
</script><br />
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></p>
<h2>Tip 2: Bruteforce?</h2>
<p>Such a rudimentary attack that people almost forget about it. And most of the time it can be invisible to the websites administrator because POST requests aren&#8217;t logged by default. You may remember this from my article <a href="http://insanesecurity.info/2009/01/logging-the-http-requests/">Logging the HTTP requests!</a> But I&#8217;m not going to use that, because I want to keep all this simple, as simple as possible. So then, we will assume we got a table which is cleared daily (cron?) and stores only the username in the table. One columned table. (I told you that I&#8217;m gonna keep it simple) Then the following lines would be also in the login script (before the login query):</p>
<pre>
$counter = mysql_result(
    mysql_query(
        "SELECT COUNT(*)
         FROM attempts
         WHERE username='$username'"
    ),
    0
);
mysql_query("INSERT INTO attempts VALUES('$username')");
if($counter&gt;=10) {
    echo 'Bruteforce attempt detected or more than allowed logins per day exceeded!';
    exit;
}
</pre>
<p>As you can see the drawback for this is that while protecting the users from bruteforce attacks, it may also (and it&#8217;s likely) to lock them out. Luckily for us there is a solution for the problem. We add another column to our table <strong>attempts</strong> of type char(2) in which we store the current hour. Basically we limit the number of logins per hour.</p>
<pre>
$counter = mysql_result(
    mysql_query(
        "SELECT COUNT(*)
         FROM attempts
         WHERE username='$username'
         AND hour='".date('G')."'"
    ),
    0
);
mysql_query("INSERT INTO attempts VALUES('$username', '".date('G')."')");
if($counter&gt;=3) {
    echo 'Max number of logins per hour exceeded!';
    exit;
}
</pre>
<p>Now it looks a little better, but still it misses something&#8230;</p>
<h2>Tip 3: IP Ban List</h2>
<p>You could use ban lists for various reasons, from allowing &#8220;known attackers&#8221; to blocking access via proxy. Generally people tend to use .htaccess files for blacklisting, but I will stick to PHP and MySQL for the example. <strong>NOTE</strong>: On medium to large websites a database (MySQL) &#8211; backend (PHP) application would stress pretty much the database. The following code should be inserted before the max number of logins per hour check.</p>
<pre>
$max_counter = mysql_result(
    mysql_query(
        "SELECT COUNT(*)
         FROM attempts
         WHERE username='$username'"
    ),
    0
);
if($max_counter&gt;9) {
    mysql_query("INSERT INTO banlist VALUES('".$_SERVER['REMOTE_ADDR']."')");
}
</pre>
<p>And the following line on the first line of the script.</p>
<pre>
if(1==mysql_num_rows(
    mysql_query(
        "SELECT 1
         FROM banlist
         WHERE ip='".$_SERVER['REMOTE_ADDR']."'"
    )
)) {
    echo 'Your IP address is in the ban list!';
    exit;
}
</pre>
<p>Of course you could dump the IP Address list from time to time from the database, but the following solution is a better one because it does not involve high stress on database.<br />
<script type="text/javascript"><!--
google_ad_client = "pub-4879499347590889";
/* 468x60, created 1/22/09 */
google_ad_slot = "0361207255";
google_ad_width = 468;
google_ad_height = 60;
//-->
</script><br />
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></p>
<h2>Tip 4: reCAPTCHA</h2>
<p>CAPTCHA is a good way to protect a web page (login page, important forms) from bruteforce and CSRF attacks. But we are not talking about self made CAPTCHA&#8217;s, you don&#8217;t have to reinvent the wheel&#8230; in a cubic form. That&#8217;s right, most of those who write there own CAPTCHA&#8217;s tend to make them weak or impossible to use (yes, Rapidshare&#8217;s CAPTCHA is one of those). You should use a good and public CAPTCHA, like reCAPTCHA. Also don&#8217;t over use them, you have to think of CAPTCHA&#8217;s like door keys. It&#8217;s very good to have one to your entrance door, but having to unlock the door for every room can be quite annoying, if not frustrating.</p>
<h2>Tip 5: Encrypted login information</h2>
<p>You either should use SSL or (if not available) frontend encryption (hashing in our case). A good example of such an implementation would be <a href="http://insanesecurity.info/2009/01/useratuh-frontend-to-backend-encryption/">userAtuh</a>&#8217;s one. You can find available md5/sha1 hashing library&#8217;s written in javascript around the web. One such an example is Paul Johnston&#8217;s <a href="http://pajhome.org.uk/crypt/md5/md5src.html">Javascript MD5</a> library which is stated to be used by Yahoo on several non SSL pages. Can&#8217;t tell if it&#8217;s true or not, didn&#8217;t check it out, but for those who know Trilulilu (especially Romanian comrades) I can tell you that they implemented it in their flash player, for &#8220;encrypting&#8221; the source of their media (did I say too much?=).</p>
<p><script type="text/javascript"><!--
google_ad_client = "pub-4879499347590889";
/* 468x60, created 1/22/09 */
google_ad_slot = "0361207255";
google_ad_width = 468;
google_ad_height = 60;
//-->
</script><br />
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></p>
<h2>Tip 6: Legitimate Requests (CSRF free)</h2>
<p>As mentioned before excessively using CAPTCHA may be annoying, except in the case that the admin panel is designated for only one person (yourself) and you can bare completing on every important request a CAPTCHA field. For the other cases you could take a similar approach. On request of a page with an important form you could generate the token in the following way.</p>
<pre>
$_SESSION['token'] = sha1(rand());
</pre>
<p>And inside the form you could place it like&#8230;</p>
<pre>
&lt;input type="hidden" name="token" value="&lt;?php echo $_SESSION['token']; ?&gt;" /&gt;
</pre>
<p>While in the form processing page you should deal with it as in the following code.</p>
<pre>
if($_SESSION['token']!=$_POST['token']) {
    exit;
}
$_SESSION['token'] = sha1(rand());
</pre>
<p>Also a better way would be by using mt_rand() and seeding it with a secret method. Like for example the sum of the numbers from the session id.</p>
<h2>Tip 7: Protect your includes/secure pages</h2>
<p>If you develop your web application in a similar manner as myself than probably you include the admin pages, rather than use one  single over bloated file. And it&#8217;s a common mistake to not protect those files from direct access. I&#8217;ve seen cases of obscure naming of the files, which are not secure if the attacker can get directory information in a way or another. Although are very interesting. Why? Because security by obscurity can be very fun an creative, even useful sometimes if build on top of a secure design. Like for example when using a MySQL database (version 4, so no information_schema database available) and obscuring the table names. Coming back to our subject, you could protect your included files by using the following line of code.</p>
<pre>
if(!defined('PROTECTED')) { exit; }
</pre>
<p>While defining the PROTECTED constant in the script which includes the files (which we assume you protect). You can secure your main files (those who include files) in a similar way.</p>
<pre>
if(!$_SESSION['auth']) { exit; }
define('PROTECTED', true);
</pre>
<h2>Tip 8: Password Change</h2>
<p>When making a password change functionality don&#8217;t forget to ask the user for their current password. Many think that if a user is logged in and no CSRF could take place they are safe and thus don&#8217;t need to ask them for their current password. It&#8217;s wrong to think like that because Session Riding attacks are more frequent than you think. And it&#8217;s not such a big deal of doing this, it only takes an extra where clause in the update syntax.</p>
<pre>
$old_password = sha1('salt'.$_POST['old_password']);
$new1 = sha1('salt'.$_POST['new1']);
$new2 = sha1('salt'.$_POST['new2']);
if($new1!=$new2) {
    echo 'Your new passwords do not match!';
    exit;
}
if(mysql_query(
    "UPDATE
     SET password='$new1'
     WHERE id='".$_SESSION['id']."'
     AND password='$old_password'"
)) {
    echo 'Password successfully changed!';
}
else {
    echo 'Password couldn\'t be changed!';
}
</pre>
<h2>Tip 0</h2>
<p>This are the most common approaches which should be taken when coding login scripts/admin panels. Also they are the most common neglected aspects. Kind of paradoxical in a way. And that;s not all, if we think of HTTP Redirects which by the way haven&#8217;t been treated because latest versions of PHP protect you against HTTP Response Splitting. Another thing I didn&#8217;t treat was XSS, which I think (and maybe you would approve) doesn&#8217;t make a part of this subject, it concerns the way you implement functionality in your pages. I often wonder why even give power to the user, like for example in a comment form. Why give him even the ability to post link (and convert them to link)?</p>
<p>Anyway, as you can see I didn&#8217;t post a ready to use script/class because I wanted you to understand the concept behind login/admin panel security. Not just copy-paste the code and cross your fingers that it will work.</p>
<p><strong>UPDATE</strong>: On <a href="http://rvdh.ath.cx/">Ronald</a>&#8217;s suggestion I replaced the md5 hashes with sha1 hashes, even salted them. Also modified the MySQL code to order the result by id, just in case there where two accounts with the same login information (which shouldn&#8217;t, if you properly did the checks in the registration page, if uses any). </p>
]]></content:encoded>
			<wfw:commentRss>http://insanesecurity.info/blog/8-tips-for-a-secure-login-scriptadmin-panel/feed</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Regain your privacy and anonymity</title>
		<link>http://insanesecurity.info/blog/regain-your-privacy-and-anonymity</link>
		<comments>http://insanesecurity.info/blog/regain-your-privacy-and-anonymity#comments</comments>
		<pubDate>Wed, 24 Jun 2009 16:31:06 +0000</pubDate>
		<dc:creator>dblackshell</dc:creator>
				<category><![CDATA[Discussion]]></category>
		<category><![CDATA[How To]]></category>
		<category><![CDATA[Anonymity]]></category>
		<category><![CDATA[Encryption]]></category>
		<category><![CDATA[Firefox]]></category>

		<guid isPermaLink="false">http://insanesecurity.info/blog/?p=58</guid>
		<description><![CDATA[Hopefully as you may have noticed, on a daily basis more and more of our (users) privacy is stripped shamelessly away by almost every website out there. And so you don&#8217;t think I am speaking in a hypocritical manner, I admit I strip as well a part from your privacy, with the simple Google tracker [...]]]></description>
			<content:encoded><![CDATA[<p>Hopefully as you may have noticed, on a daily basis more and more of our (users) privacy is stripped shamelessly away by almost every website out there.</p>
<p>And so you don&#8217;t think I am speaking in a hypocritical manner, I admit I strip as well a part from your privacy, with the simple Google tracker I have inside my web pages&#8230; but for those that do care about their anonymity this is not an issue.
</p>
<p><span id="more-58"></span></p>
<h2><a href="http://www.torproject.org">Tor</a></h2>
<p>As any other person would say, as a first step in regaining your anonymity would be installing the Tor bundle&#8230; And don&#8217;t get me that &#8220;just hackers use proxies&#8221;, because it&#8217;s not true&#8230; who would use a proxy for a <a href="http://www.liquidmatrix.org/blog/2009/04/14/commit-crime-with-a-proxy-get-25-more-buh-bye/">%25 bonus prison time if caught</a>? (they would use their own tunnels and proxies, not Tor networks)</p>
<p>There are many reasons why you would use a proxy, apart from the list which you can read on Tor projects website &#8220;<a href="http://www.torproject.org/torusers.html.en">Who uses Tor?</a>&#8220;, what better way to hide your ass when trolling people?</p>
<p>Use Tor, if possible even help out by setting up a node, and be happy of it&#8217;s extra anonymity (which I cannot have).<br />
<script type="text/javascript"><!--
google_ad_client = "pub-4879499347590889";
/* 468x60, created 1/22/09 */
google_ad_slot = "0361207255";
google_ad_width = 468;
google_ad_height = 60;
// --></script><br />
<script src="http://pagead2.googlesyndication.com/pagead/show_ads.js" type="text/javascript"></script></p>
<h2><a href="http://www.scroogle.org">Scroogle</a></h2>
<p>Well, in case you are a Google user I hope you know that every search you ever do is logged&#8230; If you have a Google account you may check your whole search history <a href="http://www.google.com/history">here</a>. Now you may see where Scroogle would come in pretty handy. It also comes with SSL support, so it also adds a part of privacy to it: <a href="https://ssl.scroogle.org">ssl.scroogle.org</a>.</p>
<p>In simple terms Scroogle does the search on Google for you, drops the cookie that Google tries to attach to your browser and prints you the output of the search.</p>
<h2><a href="http://www.bugmenot.com">BugMeNot</a></h2>
<p>Often enough websites ask you for a user account in your attempt to access their content, even if it&#8217;s going to be your first (and last) visit on their page. Well through <a href="http://www.bugmenot.com">BugMeNot</a> you can bypass that compulsory registration process.  <a href="http://www.bugmenot.com/faq.php#03">Why not just register?</a><br />
<script type="text/javascript"><!--
google_ad_client = "pub-4879499347590889";
/* 468x60, created 1/22/09 */
google_ad_slot = "0361207255";
google_ad_width = 468;
google_ad_height = 60;
// --></script><br />
<script src="http://pagead2.googlesyndication.com/pagead/show_ads.js" type="text/javascript"></script></p>
<h2><a href="http://mailinator.com">Mailinator</a></h2>
<p>In case BugMeNot didn&#8217;t have the answer for the problem (as in bypassing compulsory registration), you can quickly set up your account without having to fear spam later on. <a href="http://mailinator.com">Mailinator</a> offers you a easy one step temporary email address for any occasion, at any time you may need it.</p>
<h2><a href="http://www.gnupg.org/">GPG</a></h2>
<blockquote><p><a href="http://www.gnupg.org/">GnuPG</a> is the GNU project&#8217;s complete and free implementation of the OpenPGP standard as defined by RFC4880 . GnuPG allows to encrypt and sign your data and communication (&#8230;)</p>
</blockquote>
<p>Using PGP encryption has many benefits, given the amount of tools built upon it.<br />
For the browser (Firefox) you got <a href="http://getfiregpg.org/">FireGPG</a> which let&#8217;s you sign, verify, encrypt and decrypt anything that you can select in your browser, this even includes email, posts and so fort. It also comes with implementation for Gmail.</p>
<h2>Firefox addons</h2>
<p>There are two addons which I know help in providing anonymity.</p>
<p>One would be <a href="https://addons.mozilla.org/en-US/firefox/addon/722">NoScript</a>, which I use to block trackers (like Google Analytics), but this is just a bonus for the main reason I use it, and I mean security.</p>
<p>The second one is <a href="https://addons.mozilla.org/en-US/firefox/addon/9727">RequestPolicy</a>, which if even would look very similar to NoScript there is a finely grained difference them. I personally use both of them, and do recommend the same if you got the patience to whitelist websites you visit.<br />
<script type="text/javascript"><!--
google_ad_client = "pub-4879499347590889";
/* 468x60, created 1/22/09 */
google_ad_slot = "0361207255";
google_ad_width = 468;
google_ad_height = 60;
// --></script><br />
<script src="http://pagead2.googlesyndication.com/pagead/show_ads.js" type="text/javascript"></script></p>
<h2>IM Encryption</h2>
<p>The modern use of the internet is highly oriented on instant messaging, so this area of privacy should be taken care of with more interest than any other before told privacy measure.</p>
<p>For example the IM client <a href="http://pidgin.im">Pidgin</a> has a few <a href="http://developer.pidgin.im/wiki/ThirdPartyPlugins#SecurityandPrivacy">privacy and security plugins</a> from which you may choose.</p>
<p>As for IM clients like MSN and Yahoo! you may download (and use) <a href="http://www.bitdefender.com/PRODUCT-2236-en--BitDefender-Chat-Encryption.html">BitDefender Chat Encryption</a> for free.</p>
<h2>More suggestions?</h2>
<p>If there is something that you think I missed out (as in privacy and anonymity for internet users) feel free to contribute, even with alternatives for the before mentioned ones.</p>
]]></content:encoded>
			<wfw:commentRss>http://insanesecurity.info/blog/regain-your-privacy-and-anonymity/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>DVL 1.5 (Infectious Disease)</title>
		<link>http://insanesecurity.info/blog/dvl-15-infectious-disease</link>
		<comments>http://insanesecurity.info/blog/dvl-15-infectious-disease#comments</comments>
		<pubDate>Wed, 24 Jun 2009 05:57:47 +0000</pubDate>
		<dc:creator>dblackshell</dc:creator>
				<category><![CDATA[Research]]></category>
		<category><![CDATA[Toolbox]]></category>
		<category><![CDATA[Cracking]]></category>
		<category><![CDATA[Encryption]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[SQL Injection]]></category>
		<category><![CDATA[XSS]]></category>

		<guid isPermaLink="false">http://insanesecurity.info/blog/?p=30</guid>
		<description><![CDATA[Today DamnVulnerableLinux version 1.5 was released, linux distribution that offers a learning environment directly out of the box. If there is a phrase that describes in the best way the distribution, it has to be the one from LinuxTracker: Damn Vulnerable Linux (DVL) is everything a good Linux distribution isn&#8217;t. Its developers have spent hours [...]]]></description>
			<content:encoded><![CDATA[<p>Today <a href="http://www.damnvulnerablelinux.org/">DamnVulnerableLinux</a> version 1.5 was released, linux distribution that offers a learning environment directly out of the box.</p>
<p><span id="more-30"></span><br />
If there is a phrase that describes in the best way the distribution, it has to be the one from <a href="http://linuxtracker.org">LinuxTracker</a>:</p>
<blockquote><p>
Damn Vulnerable Linux (DVL) is everything a good Linux distribution isn&#8217;t. Its developers have spent hours stuffing it with broken, ill-configured, outdated, and exploitable software that makes it vulnerable to attacks. DVL isn&#8217;t built to run on your desktop &#8212; it&#8217;s a learning tool for security students.
</p>
</blockquote>
<p>To be honest I didn&#8217;t play with it till now (even if have been a user of the website for a year or so) because off limited free time that I&#8217;ve got. But in the near future (hope so) I will give it a shot, you know demonstrate my &#8220;talents&#8221; to my work colleague, maybe even do a video to help out DVL.</p>
<p>More specific info about included vulnerabilities/tools you can find on <a href="http://www.damnvulnerablelinux.org/index.php/eng/Damn%20Vulnerable%20Linux%20Distro/Damn%20Vulnerable%20Linux/Release%20Notes%20for%20Damn%20Vulnerable%20Linux%20(up%20to%20release%201.4)">this page</a>, but just up to version 1.4, and the download mirrors can be found <a href="http://www.damnvulnerablelinux.org/index.php/eng/Damn%20Vulnerable%20Linux%20Distro/Damn%20Vulnerable%20Linux/Download%20Mirrors%20and%20Torrent%20for%20Damn%20Vulnerable%20Linux%201.5%20(Infectious%20Disease)">here</a>.</p>
<p>If this is an unknown domain for you (security) I would recommend you firstly to start out with some basics before even taking a glimpse at DVL. In such a case you might be interested in David Melnichuk book <a href="http://insanesecurity.info/2009/01/the-hackers-underground-handbook-review/">The Hacker&#8217;s Underground Handbook</a>.</p>
<p>Before I forget&#8230; You would highly be appreciated for seeding the torrent, not just leeching it, because the free stuff never gets seeded well, IMO.</p>
]]></content:encoded>
			<wfw:commentRss>http://insanesecurity.info/blog/dvl-15-infectious-disease/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>userAtuh – frontend to backend encryption</title>
		<link>http://insanesecurity.info/blog/useratuh-%e2%80%93-frontend-to-backend-encryption</link>
		<comments>http://insanesecurity.info/blog/useratuh-%e2%80%93-frontend-to-backend-encryption#comments</comments>
		<pubDate>Wed, 24 Jun 2009 05:50:02 +0000</pubDate>
		<dc:creator>dblackshell</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[Encryption]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://insanesecurity.info/blog/?p=18</guid>
		<description><![CDATA[How many times did you check a web application of yours with a security auditing tool? I can tell you that I did it a couple of times. And as usual it always hit me with the same warning: &#8216;the login information is sent in plain text to &#8230;php&#8217;, or something of sort. And ignoring [...]]]></description>
			<content:encoded><![CDATA[<p>How many times did you check a web application of yours with a security auditing tool?<br />
I can tell you that I did it a couple of times. And as usual it always hit me with the same warning: &#8216;the login information is sent in plain text to &#8230;php&#8217;, or something of sort.</p>
<p><span id="more-18"></span><br />
And ignoring this warning is half as bad as having a sql injection vulnerability. Even if home users no longer are a part in a shared network thus sniffing is highly improbable, companies have LAN&#8217;s which would make a sniffing attack possible (if the sysadmin didn&#8217;t do his  job). Throwing away all your security implementations, password enforcements&#8230;</p>
<p>SSL is the solution for this case but isn&#8217;t necesarily needed. Here comes in <a href="http://sourceforge.net/projects/useratuh/">userAtuh</a>. Yes it&#8217;s a typo, but who cares how it&#8217;s called as long as it does a great job?</p>
<p><strong>UserAtuh</strong> is a php/js library used for serverside/client side password encryption, ment to mask the password sent by login forms. You can download it from it&#8217;s <a href="http://sourceforge.net/projects/useratuh/">project page on SourceForge</a>.</p>
<p><script type="text/javascript"><!--
google_ad_client = "pub-4879499347590889";
/* 468x60, created 1/22/09 */
google_ad_slot = "0361207255";
google_ad_width = 468;
google_ad_height = 60;
//-->
</script><br />
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></p>
<p>How does it work? Actually it&#8217;s quite straight forward, but I could better show it&#8217;s working by pointing out the key portions of code.</p>
<p>It all starts with the login form with has defined to the on submit event assigned to the <strong>setEncryption()</strong> function, which: hashes the password, joins it with the username and key and double hashes the result storing it in a hidden input field.</p>
<p>Upon form submision the only two values that are requested are the username and the result of the <strong>setEncryption()</strong> function. The rest is ignored. Forgot to mention that the <strong>setEncryption()</strong> function also changes the password from the input field with a substring of its result.</p>
<p>The authentification is done by the function with the same name from the <strong>KeyHandler</strong> object:</p>
<pre>
public function authenticate($name,$encodedPass,$sha1=true){
    //get the last key that was generated for this
    //session
    $ip = getenv('REMOTE_ADDR');
    $key  = $this->_dba->getKeyFromDB($ip);

    //check if a user exists with this name
    if ($this->_dba->userExists($name)==false) return false;    	

    //retrive the password for the user
    $pass = $this->_dba->getPass($name);

    //make sure password is hashed
    if (!$sha1) $pass = sha1($pass);

    //create a hashed string from the date collected
    $encoded = sha1(sha1($pass.$name.$key));

    //generate a new key, so the last key won't be usable
    $this->generateKey();

    //check the hashed string with the key sent by the
    //client side
    return ($encodedPass==$encoded);
}
</pre>
<p>Simple, easy, useful. It&#8217;s implementation can take at maximum a couple of minutes. Quick and painless, just as I like &#8216;em.</p>
]]></content:encoded>
			<wfw:commentRss>http://insanesecurity.info/blog/useratuh-%e2%80%93-frontend-to-backend-encryption/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
