The Arcive of Official vBulletin Modifications Site.It is not a VB3 engine, just a parsed copy! |
|
Secure BCrypt Password Hashing Details »» | ||||||||||||||||||||||||||
This is a 'howto' for using bcrypt for your password hashs, instead of the default vBulletin one, which is highly insecure.
Remember, backup your database before doing this!! Quote:
More information about BCrypt can be found here: http://codahale.com/how-to-safely-store-a-password/ - http://phpmaster.com/why-you-should-...red-passwords/ tl;dr: if you want to be moar secure, use bcrypt. " How much slower is bcrypt than, say, MD5? Depends on the work factor. Using a work factor of 12, bcrypt hashes the password 'password' in about 0.3 seconds on my laptop. MD5, on the other hand, takes less than a nanosecond." BEFORE YOU DO THIS, PLEASE CREATE A .PHP FILE WITH THIS IN IT Code:
<?php if (defined("CRYPT_BLOWFISH") && CRYPT_BLOWFISH) { echo "CRYPT_BLOWFISH is enabled!"; } else { echo "CRYPT_BLOWFISH is not available"; } /includes/functions.php Add this to the end, just before the footer message. Code:
/** * * Hash 'password' using the crypt() function w/ bcrypt * Use the first 21 characters of the MD5(strrev($salt)) as our bcrypt salt * Return the MD5 return of this crypt() call, to maintain database functionality. The main part of our security is kept(making hashing, thus cracking, longer). * This should always be called like hash_password_bcrypt(md5(md5($password) . $salt), $salt) **/ function hash_password_bcrypt($password, $salt) { //You may set this to your liking. A higher cost means it will take longer for the password to hash. 15 seems to be a good value. $cost = 15; // must be in range 04 - 31 return md5(crypt($password, '$2y$' . $cost . '$' . substr(md5(strrev($salt)),0,21) . '$')); } includes/class_dm_user.php Now.. Find this: Code:
if ($password == md5(md5($this->fetch_field('username')) . $salt)) Code:
if ($password == $this->hash_password($this->fetch_field('username'), $salt)) Then, on the same file, replace this: Code:
return md5($password . $salt); Code:
//No need to md5($password), since it is already md5'd above. return hash_password_bcrypt(md5($password . $salt), $salt); includes/functions_login.php Find this: Code:
$vbulletin->userinfo['password'] != iif($password AND !$md5password, md5(md5($password) . $vbulletin->userinfo['salt']), '') AND $vbulletin->userinfo['password'] != iif($md5password, md5($md5password . $vbulletin->userinfo['salt']), '') AND $vbulletin->userinfo['password'] != iif($md5password_utf, md5($md5password_utf . $vbulletin->userinfo['salt']), '') Code:
$vbulletin->userinfo['password'] != iif($password AND !$md5password, hash_password_bcrypt(md5(md5($password) . $vbulletin->userinfo['salt']), $vbulletin->userinfo['salt']), '') AND $vbulletin->userinfo['password'] != iif($md5password, hash_password_bcrypt(md5($md5password . $vbulletin->userinfo['salt']), $vbulletin->userinfo['salt']), '') AND $vbulletin->userinfo['password'] != iif($md5password_utf, hash_password_bcrypt(md5($md5password_utf. $vbulletin->userinfo['salt']), $vbulletin->userinfo['salt']), '') So effectively, we are hashing the password using the normal vBulletin way of md5(md5($password) . $vbulletin->userinfo['salt']) however after doing that, we then run hash_password_bcrypt() around it. By doing it this way, we can now convert our old hashes to the new bcrypt method. Create a file called "convert.php", with the contents: Code:
<?php require("./global.php"); set_time_limit(0); ini_set('max_execution_time',0); $q = $db->query_read("select userid, username, password, salt from user WHERE password != ''"); echo "Updating " . $db->num_rows($q) . " accounts.<br />\n"; while($r = $db->fetch_array($q)){ $db->query_write("UPDATE user SET password = '" . hash_password_bcrypt($r['password'], $r['salt']) . "' WHERE userid = '" . $r['userid'] . "'"); echo "Updated password for " . htmlspecialchars($r['username']) . "<br />\n"; } echo "Finished.<br />\n"; ?> Show Your Support
|
2 благодарности(ей) от: | ||
Brandon Sheley, ChiNa |
Comments |
#12
|
|||
|
|||
Oh. I see what you mean. I thought you were referring to hash cracking.
MD5 collisions aren't such a problem in vBulletin, really. + Also, it would take a lot longer to find a hash collision... |
#13
|
||||
|
||||
It has nothing to do with vBulletin.
If someone hacks into your server and gets your database dump, they can brute force that to find other possible passwords for your users. The whole point of BCrypt is to make that impossible by A) being ridiculously slow, and B) being a more crytographically unique hash. |
#14
|
|||
|
|||
Quote:
First of all, if they cracked the MD5, what would they get? They would get the bcrypt value. Then what? Then they have to crack that. That's the pointy. |
#15
|
|||
|
|||
Quote:
Dictionary Attacks, or Rainbow Tables or hash collisions? Hash collisions aren't useful, afaik.. they just let you login to your account(or NOT your account) with more than just one password. |
#16
|
|||
|
|||
NICE
this rocks |
#17
|
|||
|
|||
I have a feeling that after using this, the forums login/reset wise is actually much slower.
|
#18
|
|||
|
|||
Quote:
Note: the slower the algorithm (and amount of iterations/cost), the longer it takes to brute force passwords, which is a good thing. |
#19
|
|||
|
|||
If you look at the second piece of code posted above there's a "cost" factor which can be adjusted so that users don't see an objectionable delay.
|
#20
|
|||
|
|||
Updated with a method to set passwords
|
#21
|
|||
|
|||
Great Job and a Very good Idea. I have had my friends vB4.x forums hacked where the hackers later Published all forum Users Usernames, Email, and MD5 Password Hashes out in Public. I know by facts that they hacked their way in by decrypting the Admin Password somehow. And NOT by Brute Forcing their way in. We suspected that they got in because of a Custom Skin installed on the forum that was vulnerable.
I am not saying its not possible to Hack or Decrypt a Password by Brute Forcing, But I would rather Secure my forum and Passwords a bit Extra than just leaving the doors open and Welcome them! At least they would use more time to Crack the Passwords. Thumbs up and Well Done. Ps, I asssume you could use the same method for vB3.8. So I hope you will create a version for vBulletin 3.8 Users too. |
Thread Tools | |
|
|
X vBulletin 3.8.12 by vBS Debug Information | |
---|---|
|
|
More Information | |
Template Usage:
Phrase Groups Available:
|
Included Files:
Hooks Called:
|