|
Message-ID: <AANLkTimLbNNrh4caMcQ1hkkrS=Mgecph-1FDuUQDQWH5@mail.gmail.com> Date: Mon, 29 Nov 2010 16:08:09 -0500 From: Rich Rumble <richrumble@...il.com> To: john-users@...ts.openwall.com Subject: Re: PHP Script to Hash Plain-text input to LM/NTLM Small correction, all 14+ passes were null'd, so here is the corrected version so that NTLM can still be hashed: (sorry to spam, it was bugging me when I realized it after I sent) <?php //Cobbled together by RichRumble, Xinn.org //Code used is from: //http://www.php.net/manual/en/ref.hash.php#84587 //http://www.php.net/manual/en/ref.hash.php#94990 header("Content-Type: text/plain"); function NTLMHash($Input) { $Input=iconv('UTF-8','UTF-16LE',$Input); //$MD4Hash=bin2hex(mhash(MHASH_MD4,$Input)); $MD4Hash=hash('md4',$Input); $NTLMHash=strtoupper($MD4Hash); // Return the result return($NTLMHash); }; function LMhash($Input) { $Input = strtoupper(substr($Input,0,14)); $p1 = LMhash_DESencrypt(substr($Input, 0, 7)); $p2 = LMhash_DESencrypt(substr($Input, 7, 7)); return strtoupper($p1.$p2); }; function LMhash_DESencrypt($Input) { $key = array(); $tmp = array(); $len = strlen($Input); for ($i=0; $i<7; ++$i) $tmp[] = $i < $len ? ord($Input[$i]) : 0; $key[] = $tmp[0] & 254; $key[] = ($tmp[0] << 7) | ($tmp[1] >> 1); $key[] = ($tmp[1] << 6) | ($tmp[2] >> 2); $key[] = ($tmp[2] << 5) | ($tmp[3] >> 3); $key[] = ($tmp[3] << 4) | ($tmp[4] >> 4); $key[] = ($tmp[4] << 3) | ($tmp[5] >> 5); $key[] = ($tmp[5] << 2) | ($tmp[6] >> 6); $key[] = $tmp[6] << 1; $is = mcrypt_get_iv_size(MCRYPT_DES, MCRYPT_MODE_ECB); $iv = mcrypt_create_iv($is, MCRYPT_RAND); $key0 = ""; foreach ($key as $k) $key0 .= chr($k); //Each keys is used to DES-encrypt the constant ASCII string "KGS!@#$%" //(resulting in two 8-byte ciphertext values). $LMHash = mcrypt_encrypt(MCRYPT_DES, $key0, "KGS!@#$%", MCRYPT_MODE_ECB, $iv); return bin2hex($LMHash); }; $array = file("pt-input.txt"); $a = 0; foreach ($array as $line) { $line = trim($line); if (strlen($line) > 14) { $NTLMout = NTLMHash($line); $LMout = LMHash(""); } else { $NTLMout = NTLMHash($line); $LMout = LMHash($line); }; print "user-" . $a++ . ":0:" . $LMout . ":" . $NTLMout . ":::" . "\n"; }; ?> -rich
Powered by blists - more mailing lists
Confused about mailing lists and their use? Read about mailing lists on Wikipedia and check out these guidelines on proper formatting of your messages.