Hallo!Ich habe versucht, mir den Code aus Webmin zu pflücken:
use MD5;
use Digest::MD5;local $passwd = $query{'pass'};
local $magic = '$1$';
local $salt = $_[1] || substr(time(), -8);
local $ctx = new Digest::MD5;
$ctx->add($passwd);
$ctx->add($magic);
$ctx->add($salt);
# Add some more stuff from the hash of the password and salt
local $ctx1 = new Digest::MD5;
$ctx1->add($passwd);
$ctx1->add($salt);
$ctx1->add($passwd);
local $final = $ctx1->digest();
for($pl=length($passwd); $pl>0; $pl-=16)
{
$ctx->add($pl > 16 ? $final : substr($final, 0, $pl));
}
# This piece of code seems rather pointless, but it's in the C code that
# does MD5 in PAM so it has to go in!
local $j = 0;
local ($i, $l);
for($i=length($passwd); $i; $i >>= 1)
{
if ($i & 1)
{
$ctx->add("\0");
}
else
{
$ctx->add(substr($passwd, $j, 1));
}
}
$final = $ctx->digest();
# This loop exists only to waste time
for($i=0; $i<1000; $i++)
{
$ctx1 = new Digest::MD5;
$ctx1->add($i & 1 ? $passwd : $final);
$ctx1->add($salt) if ($i % 3);
$ctx1->add($passwd) if ($i % 7);
$ctx1->add($i & 1 ? $final : $passwd);
$final = $ctx1->digest();
}
# Convert the 16-byte final string into a readable form
local $rv = $magic.$salt.'$';
local @final = map { ord($_) } split(//, $final);
$l = ($final[ 0]<<16) + ($final[ 6]<<8) + $final[12];
$rv .= &to64($l, 4);
$l = ($final[ 1]<<16) + ($final[ 7]<<8) + $final[13];
$rv .= &to64($l, 4);
$l = ($final[ 2]<<16) + ($final[ 8]<<8) + $final[14];
$rv .= &to64($l, 4);
$l = ($final[ 3]<<16) + ($final[ 9]<<8) + $final[15];
$rv .= &to64($l, 4);
$l = ($final[ 4]<<16) + ($final[10]<<8) + $final[ 5];
$rv .= &to64($l, 4);
$l = $final[11];
$rv .= &to64($l, 2);
$cryptpass=$rv;
@itoa64 = split(//, "./0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz");
sub to64
{
local ($v, $n) = @_;
local $r;
while(--$n >= 0)
{
$r .= $itoa64[$v & 0x3f];
$v >>= 6;
}
return $r;
}
Oder die andere Möglichkeit auch aus Webmin:
$salt = chr(int(rand(26))+65) . chr(int(rand(26))+65);
$cryptpass=crypt($pass, $salt);
Leider kenne ich die beiden oberern Module nicht. Aber das ergebnis, das ich erhalte ist falsch. Bei der zweiten Möglichkeit kenne ich mich aus, nur verstehe ich nicht, wie das gehen soll. Wenn ich mit einem Zufallsstring verschlüssle, kommt doch immer ein anderes Ergebnis raus...
mfg, Speed
Datum: 19.11.2004-08:44
