MD5 crypting
Preston Kutzner
shizzlecash at gmail.com
Fri May 1 05:27:01 UTC 2009
On Apr 27, 2009, at 12:35 PM, Brian McKee wrote:
> On Mon, Apr 27, 2009 at 1:12 PM, NoOp <glgxg at sbcglobal.net> wrote:
>> On 04/26/2009 12:29 PM, Arda Eden wrote:
>>> The other interesting thing is every encryption with grub-md5-
>>> crypt for the
>>> same password generates different hashes.
>> It should give you different hashes each time.
>
> Can you explain why it does that? (I've confirmed you are indeed
> correct)
> Like the OP I would have thought it would be the same each time.
> For instance - this is the same every time.
>> echo '<?php echo crypt("password", "xy") ?>' | php
>> xyAjYtmfRYx/.
The hashes are different each time it's run because md5-hashed
passwords (just like crypted passwords) use a randomly generated salt
each time. The salt for an MD5-hashed password comes from a specific
character set and is 8 characters in length.
>
> Is there a salt in there somewhere? If so, how does grub know what
> the salt is?
You can find the salt of an md5-hashed password just by looking at
it. Here's an example password:
$1$S2DicXTU$gDrqCB/13hPrU/gdnCvZC1
The dollar-signs '$' are field delimiters in the hashed password. The
'1' after the first '$' denotes that this is an md5-hashed password.
Everything between the 2nd and 3rd '$' is the salt, in this case
'S2DicXTU'. Everything after the 3rd '$' is the hashed value of the
combination of the salt and the plain-text password. It's not a
standard md5 sum as you would get if you were to do something like
'echo -n "S2DicXTUpassword" | md5sum'. Here's a quote from Wikipedia:
"First the passphrase and salt are hashed together, yielding an MD5
message digest. Then a new digest is constructed, hashing together the
passphrase, the salt, and the first digest, all in a rather complex
form. Then this digest is passed through a thousand iterations of a
function which rehashes it together with the passphrase and salt in a
manner that varies between rounds. The output of the last of these
rounds is the resulting passphrase hash."
When grub or pam checks your passphrase, it doesn't actually decrypt
the has and check your entered password against the decrypted one, it
just re-hashes the password you entered, using the same salt and
compares the results. If they match, it means you entered the correct
password, if not, obviously you didn't.
Here's an example perl program that will give you an md5-hashed
password:
#!/opt/local/bin/perl -w
use strict;
use warnings;
use Crypt::PasswdMD5;
my $salt = (join '', ('.','/', 0..9, 'A'..'Z', 'a'..'z') [rand 64,
rand 64, rand 64, rand 64, rand 64, rand 64, rand 64, rand 64]);
my $password;
if ( $ARGV[0] eq "" ) {
system "stty -echo";
print "Password: ";
chomp($password = <STDIN>);
print "\n";
system "stty echo";
} else {
chomp( $password = $ARGV[0] );
}
print "MD5 Crypted Password: ";
print unix_md5_crypt($password,$salt)."\n";
exit 0;
You can also get one using openssl as follows:
$ echo -n "password" | openssl passwd -1 -stdin
>
> Hopefully this doesn't qualify as thread jacking - I think the OP has
> the same question.
>
> Brian
>
> --
> ubuntu-users mailing list
> ubuntu-users at lists.ubuntu.com
> Modify settings or unsubscribe at: https://lists.ubuntu.com/mailman/listinfo/ubuntu-users
--
A: Because it messes up the order in which people normally read text.
Q: Why is top-posting such a bad thing?
More information about the ubuntu-users
mailing list