For thoes of you who're looking to generate an NTLM hash (not an LM hash), I found out it's quite simple..
It uses the basic MD4 function, but the password needs to be in Unicode Little Endian encode first (this canbe achieved by the iconv function).
This can be done easily by using the following code:
<?php
function NTLMHash($Input) {
// Convert the password from UTF8 to UTF16 (little endian)
$Input=iconv('UTF-8','UTF-16LE',$Input);
// Encrypt it with the MD4 hash
$MD4Hash=bin2hex(mhash(MHASH_MD4,$Input));
// You could use this instead, but mhash works on PHP 4 and 5 or above
// The hash function only works on 5 or above
//$MD4Hash=hash('md4',$Input);
// Make it uppercase, not necessary, but it's common to do so with NTLM hashes
$NTLMHash=strtoupper($MD4Hash);
// Return the result
return($NTLMHash);
}
?>
To produce an LM hash requires a fully-written script containing the algorithm used to make it.
Enjoy,
CraquePipe.
PHP.mk документација
Функции за хеширање
Почист и полокален преглед на PHP референцата, со задржана структура од PHP.net и подобра читливост за примери, секции и белешки.
Патека
ref.hash.php
Локална патека за оваа страница.
Извор
php.net/manual/en
Оригиналниот HTML се реупотребува и локално се стилизира.
Режим
Прокси + преведен приказ
Кодовите, табелите и белешките остануваат читливи во истиот тек.
Референца
ref.hash.php
Функции за хеширање
Референца за `ref.hash.php` со подобрена типографија и навигација.
Функции за хеширање
Содржина
- hash — Генерира вредност на хеш (дигест на порака)
- hash_algos — Враќа список на регистрирани алгоритми за хеширање
- hash_copy — Копира контекст за хеширање
- hash_equals — Безбедно споредување на низи отпорно на напади со време
- hash_file — Генерирајте вредност на хеш користејќи ја содржината на датотеката
- hash_final — Финализирајте инкрементален хеш и вратете го добиениот дигест
- hash_hkdf — Генерирајте изведување на клуч HKDF од даден влез на клуч
- hash_hmac — Генерирајте хеш вредност со клуч користејќи го методот HMAC
- hash_hmac_algos — Вратете листа на регистрирани алгоритми за хеширање погодни за hash_hmac
- hash_hmac_file — Генерирајте хеш вредност со клуч користејќи го методот HMAC и содржината на датотеката
- hash_init — Иницијализирајте контекст за инкрементално хеширање
- hash_pbkdf2 — Генерирајте изведување на клуч PBKDF2 од дадена лозинка
- hash_update — Пумпајте податоци во активен контекст за хеширање
- hash_update_file — Пумпајте податоци во активен контекст за хеширање од датотека
- hash_update_stream — Пумпајте податоци во активен контекст за хеширање од отворен стрим
Белешки од корисници 4 белешки
CraquePipe ¶
пред 18 години
артем на it-nt dot ru ¶
пред 17 години
And some code for LM hash:
<?php
function LMhash($string)
{
$string = strtoupper(substr($string,0,14));
$p1 = LMhash_DESencrypt(substr($string, 0, 7));
$p2 = LMhash_DESencrypt(substr($string, 7, 7));
return strtoupper($p1.$p2);
}
function LMhash_DESencrypt($string)
{
$key = array();
$tmp = array();
$len = strlen($string);
for ($i=0; $i<7; ++$i)
$tmp[] = $i < $len ? ord($string[$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);
$crypt = mcrypt_encrypt(MCRYPT_DES, $key0, "KGS!@#$%", MCRYPT_MODE_ECB, $iv);
return bin2hex($crypt);
}
?>
Some optimization?
кунгла на gmail dot com ¶
пред 16 години
For Samba ueserPassword you can use:
(I am not very sure aboute the salt part, but it works for me like that)
<?php
function CRYPThash($string, $salt = null)
{
if (!$salt)
$salt = rand(10,99);
return "{CRYPT}".crypt($string, $salt);
}
?>
In posted NTLMHash function you can also use:
<?php
// Encrypt it with the MD4 hash
$MD4Hash=hash('md4',$Input);
?>
So you don't need to install mhash libraries
окартер на mirabeau dot nl ¶
пред 16 години
Note for FreeBSD with PHP-5.
This is disabled by default; use the security/php5-hash port:
cd /usr/ports/security/php5-hash ; make install clean
(do not use the security/pecl-hash port as in the past, see the /usr/ports/UPDATING post from 20081211)