25 #include <winpr/ntlm.h>
26 #include <winpr/ssl.h>
27 #include <winpr/assert.h>
50 static WINPR_NORETURN(
void usage_and_exit(
void))
52 printf(
"winpr-hash: NTLM hashing tool\n");
53 printf(
"Usage: winpr-hash -u <username> -p <password> [-d <domain>] [-f <_default_,sam>] [-v "
58 int main(
int argc,
char* argv[])
62 unsigned long version = 1;
65 size_t UserLength = 0;
67 size_t DomainLength = 0;
68 char* Password = NULL;
69 size_t PasswordLength = 0;
74 if (strcmp(
"-d", argv[index]) == 0)
80 printf(
"missing domain\n\n");
86 else if (strcmp(
"-u", argv[index]) == 0)
92 printf(
"missing username\n\n");
98 else if (strcmp(
"-p", argv[index]) == 0)
104 printf(
"missing password\n\n");
108 Password = argv[index];
110 else if (strcmp(
"-v", argv[index]) == 0)
116 printf(
"missing version parameter\n\n");
120 version = strtoul(argv[index], NULL, 0);
122 if (((version != 1) && (version != 2)) || (errno != 0))
124 printf(
"unknown version %lu \n\n", version);
128 else if (strcmp(
"-f", argv[index]) == 0)
134 printf(
"missing format\n\n");
138 if (strcmp(
"default", argv[index]) == 0)
140 else if (strcmp(
"sam", argv[index]) == 0)
143 else if (strcmp(
"-h", argv[index]) == 0)
151 if ((!User) || (!Password))
153 printf(
"missing username or password\n\n");
156 winpr_InitializeSSL(WINPR_SSL_INIT_DEFAULT);
158 UserLength = strlen(User);
159 PasswordLength = strlen(Password);
160 DomainLength = (Domain) ? strlen(Domain) : 0;
162 WINPR_ASSERT(UserLength <= UINT32_MAX);
163 WINPR_ASSERT(PasswordLength <= UINT32_MAX);
164 WINPR_ASSERT(DomainLength <= UINT32_MAX);
170 printf(
"missing domain (version 2 requires a domain to specified)\n\n");
174 if (!NTOWFv2A(Password, (UINT32)PasswordLength, User, (UINT32)UserLength, Domain,
175 (UINT32)DomainLength, NtHash))
177 (void)fprintf(stderr,
"Hash creation failed\n");
183 if (!NTOWFv1A(Password, (UINT32)PasswordLength, NtHash))
185 (void)fprintf(stderr,
"Hash creation failed\n");
192 for (
int idx = 0; idx < 16; idx++)
193 printf(
"%02" PRIx8
"", NtHash[idx]);
197 else if (format == 1)
201 if (DomainLength > 0)
202 printf(
"%s:", Domain);
208 for (
int idx = 0; idx < 16; idx++)
209 printf(
"%02" PRIx8
"", NtHash[idx]);