Skip to content

Instantly share code, notes, and snippets.

@acidprime
Created December 8, 2011 02:42
Show Gist options
  • Save acidprime/1445880 to your computer and use it in GitHub Desktop.
Save acidprime/1445880 to your computer and use it in GitHub Desktop.
Perl Shadow Hash Generator
#!/usr/bin/perl
use Digest::SHA1 qw(sha1_hex);;
$password = $ARGV[0];
sub genShadowHash($){
# get our salt integer, and it's hex value
$salt = rand(2**31-1);
$saltHex = sprintf("%X",$salt);
# get string representation of bytes
$saltStr = pack("N", $salt);
# compute salted hash. get uppercase values
$sha1_salt = sprintf ("%08s%s", uc($saltHex),uc(sha1_hex($saltStr.$password)));
# blank out other hashes
$NTLM = 0 x 64;
$sha1 = 0 x 40;
$cram_md5 = 0 x 64;
$recoverable = 0 x 1024;
$string = $NTLM . $sha1 . $cram_md5 . $sha1_salt . $recoverable;
return "$string"
}
print &genShadowHash()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment