Lines 30-35
Link Here
|
30 |
#include "libcli/auth/libcli_auth.h" |
30 |
#include "libcli/auth/libcli_auth.h" |
31 |
#include "pstring.h" |
31 |
#include "pstring.h" |
32 |
|
32 |
|
|
|
33 |
#define SMB_HASH_LM 1 |
34 |
#define SMB_HASH_NTLM 2 |
35 |
|
33 |
/* |
36 |
/* |
34 |
This implements the X/Open SMB password encryption |
37 |
This implements the X/Open SMB password encryption |
35 |
It takes a password ('unix' string), a 8 byte "crypt key" |
38 |
It takes a password ('unix' string), a 8 byte "crypt key" |
Lines 57-62
Link Here
|
57 |
return ret; |
60 |
return ret; |
58 |
} |
61 |
} |
59 |
|
62 |
|
|
|
63 |
/* |
64 |
Support for using LM/NTLM hashes -- jmk@foofus.net 10/2006 |
65 |
Greets: Foofus, Phenfen, Omi, Fizzgig, pMonkey |
66 |
*/ |
67 |
void E_set_hash(int type, unsigned char hash[16]) |
68 |
{ |
69 |
uint l; |
70 |
pstring p; |
71 |
int i, j; |
72 |
char HexChar; |
73 |
int HexValue; |
74 |
|
75 |
if ( (getenv("SMBHASH")) && (strlen(getenv("SMBHASH")) == 65) ) |
76 |
{ |
77 |
pstrcpy(p, getenv("SMBHASH")); |
78 |
|
79 |
for (i=0; i<16; i++) { |
80 |
HexValue = 0x0; |
81 |
for (j=0; j<2; j++) { |
82 |
if (type == SMB_HASH_LM) |
83 |
HexChar = (char)p[2*i+j]; |
84 |
else |
85 |
HexChar = (char)p[2*i+j+33]; |
86 |
|
87 |
if (HexChar > 0x39) |
88 |
HexChar = HexChar | 0x20; /* convert upper case to lower */ |
89 |
|
90 |
if (!(((HexChar >= 0x30) && (HexChar <= 0x39))|| /* 0 - 9 */ |
91 |
((HexChar >= 0x61) && (HexChar <= 0x66)))) { /* a - f */ |
92 |
fprintf(stderr, "Error invalid char (%c) for hash.\n", HexChar); |
93 |
exit(1); |
94 |
} |
95 |
|
96 |
HexChar -= 0x30; |
97 |
if (HexChar > 0x09) /* HexChar is "a" - "f" */ |
98 |
HexChar -= 0x27; |
99 |
|
100 |
HexValue = (HexValue << 4) | (char)HexChar; |
101 |
} |
102 |
hash[i] = (unsigned char)HexValue; |
103 |
} |
104 |
} |
105 |
else |
106 |
{ |
107 |
fprintf(stderr, "Error reading SMB HASH.\n"); |
108 |
fprintf(stderr, "\tEx: export SMBHASH=\"_LM_HASH_:_NTLM_HASH_\"\n"); |
109 |
exit(1); |
110 |
} |
111 |
} |
112 |
/* jmk */ |
113 |
|
60 |
/** |
114 |
/** |
61 |
* Creates the MD4 Hash of the users password in NT UNICODE. |
115 |
* Creates the MD4 Hash of the users password in NT UNICODE. |
62 |
* @param passwd password in 'unix' charset. |
116 |
* @param passwd password in 'unix' charset. |
Lines 68-73
Link Here
|
68 |
int len; |
122 |
int len; |
69 |
void *wpwd; |
123 |
void *wpwd; |
70 |
|
124 |
|
|
|
125 |
/* Support for using NTLM hashes -- jmk@foofus.net 03/2007 */ |
126 |
if ( getenv("SMBHASH") ) { |
127 |
fprintf(stderr, "HASH PASS: Substituting user supplied NTLM HASH...\n"); |
128 |
E_set_hash(SMB_HASH_NTLM, p16); |
129 |
} else { |
71 |
len = push_ucs2_talloc(NULL, &wpwd, passwd); |
130 |
len = push_ucs2_talloc(NULL, &wpwd, passwd); |
72 |
if (len < 2) { |
131 |
if (len < 2) { |
73 |
/* We don't want to return fixed data, as most callers |
132 |
/* We don't want to return fixed data, as most callers |
Lines 81-86
Link Here
|
81 |
|
140 |
|
82 |
talloc_free(wpwd); |
141 |
talloc_free(wpwd); |
83 |
return True; |
142 |
return True; |
|
|
143 |
} |
84 |
} |
144 |
} |
85 |
|
145 |
|
86 |
/** |
146 |
/** |
Lines 97-102
Link Here
|
97 |
fstring dospwd; |
157 |
fstring dospwd; |
98 |
ZERO_STRUCT(dospwd); |
158 |
ZERO_STRUCT(dospwd); |
99 |
|
159 |
|
|
|
160 |
/* Support for using LM hashes -- jmk@foofus.net 10/2006 */ |
161 |
if ( getenv("SMBHASH") ) { |
162 |
fprintf(stderr, "HASH PASS: Substituting user supplied LM HASH...\n"); |
163 |
E_set_hash(SMB_HASH_LM, p16); |
164 |
} else { |
100 |
/* Password must be converted to DOS charset - null terminated, uppercase. */ |
165 |
/* Password must be converted to DOS charset - null terminated, uppercase. */ |
101 |
push_string(dospwd, passwd, sizeof(dospwd), STR_ASCII|STR_UPPER|STR_TERMINATE); |
166 |
push_string(dospwd, passwd, sizeof(dospwd), STR_ASCII|STR_UPPER|STR_TERMINATE); |
102 |
|
167 |
|
Lines 108-113
Link Here
|
108 |
} |
173 |
} |
109 |
|
174 |
|
110 |
ZERO_STRUCT(dospwd); |
175 |
ZERO_STRUCT(dospwd); |
|
|
176 |
} |
111 |
|
177 |
|
112 |
return ret; |
178 |
return ret; |
113 |
} |
179 |
} |