Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#!/usr/bin/php
<?php
#
# shadowHash - script to automate creating MacOS 10.4/10.5 shadow hash files
#
#
# usage: shadowHash password
#
# in most cases you'll want to redirect this to a file with the GUID of the user whose password you
# wish to set. i.e. ./shadowHash mypassword>C78F3A60-FC1D-4377-AD7D-DBAD5A6B8B2C
#
# 2008 Pete Akins, Cincinnati, OH . pete.akins@uc.edu
/*********************
FORMAT OF SHADOW FILE
Offsets and length (hex values)
0-63 NTLM Password (64)
64-103 SHA1 Digest (40)
104-167 CRAM-MD5 (64)
168-215 Salted SHA1 (48, 8+40)
216-1239 Recoverable (1024)
*********************/
if (!isset($argv[1])) {
fprintf(STDERR, "Enter password: ");
$password = trim(fgets(STDIN));
} else {
// get the password as an arg
$password = $argv[1];
}
if (empty($password)) {
die("Invalid password");
}
do {
/* make sure we get a big random number, but not too big */
$randmax = getrandmax();
$max = pow(2, 31)-1;
if ($max>$randmax) {
$max = $randmax;
}
/* get our salt integer, and it's hex value */
$salt = rand(1, $max);
$saltHex = decHex($salt);
/* get string representation of bytes */
$saltStr = pack("N", $salt);
/* compute salted hash. get uppercase values */
$sha1_salt = sprintf("%08s%s", strtoupper($saltHex), strtoupper(sha1($saltStr . $password)));
} while (strlen($sha1_salt)!=48); //just in case we have odd ball integers that result in non standard hex.
/* blank out other hashes */
$NTLM = str_repeat("0", 64);
$sha1 = str_repeat("0", 40);
$cram_md5 = str_repeat("0", 64);
$recoverable = str_repeat("0", 1024);
/* put it all together */
$string = $NTLM . $sha1 . $cram_md5 . $sha1_salt . $recoverable;
echo $string;
exit(0);
?>