cdenley
May 9th, 2007, 10:05 PM
I'm trying to write a php function that can generate an LM hash for samba. The hash it creates does not match existing hashes in the configuration. I know I have the right password, because the NT hash does match. I'm pretty sure I'm using the right encryption method, because on passwords shorter than 8 characters, the second half of the LM hash matches. I'm not sure how to test it, since I don't have any Windows 9x clients, but from what I read, the hash is always going to be the same for a given password.
function lmhash($lmpass)
{
$lmpass=strtoupper($lmpass);
if(strlen($lmpass)>14)
$lmpass=substr($lmpass,0,14);
while(strlen($lmpass)<14)
{
$lmpass.=chr(0);
}
$lmstr="KGS!@#$%";
$half=substr($lmpass,0,7);
$ret =strtoupper(bin2hex(mcrypt_ecb(MCRYPT_DES,$half,$l mstr,MCRYPT_ENCRYPT,mcrypt_create_iv(8))));
$half=substr($lmpass,7);
$ret.=strtoupper(bin2hex(mcrypt_ecb(MCRYPT_DES,$ha lf,$lmstr,MCRYPT_ENCRYPT,mcrypt_create_iv(8))));
return $ret;
}
function lmhash($lmpass)
{
$lmpass=strtoupper($lmpass);
if(strlen($lmpass)>14)
$lmpass=substr($lmpass,0,14);
while(strlen($lmpass)<14)
{
$lmpass.=chr(0);
}
$lmstr="KGS!@#$%";
$half=substr($lmpass,0,7);
$ret =strtoupper(bin2hex(mcrypt_ecb(MCRYPT_DES,$half,$l mstr,MCRYPT_ENCRYPT,mcrypt_create_iv(8))));
$half=substr($lmpass,7);
$ret.=strtoupper(bin2hex(mcrypt_ecb(MCRYPT_DES,$ha lf,$lmstr,MCRYPT_ENCRYPT,mcrypt_create_iv(8))));
return $ret;
}