The FreeRADIUS server  $Id: 15bac2a4c627c01d1aa2047687b3418955ac7f00 $
smbencrypt.c
Go to the documentation of this file.
1 /*
2  * smbencrypt.c Produces LM-Password and NT-Password from
3  * cleartext password
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
18  *
19  * @copyright 2002 3APA3A for FreeRADIUS project
20  @copyright 2006 The FreeRADIUS server project
21  */
22 
23 RCSID("$Id: 6054089af296bf4d0338527b7eb06ead7dc3d4cf $")
24 
25 #include <freeradius-devel/util/misc.h>
26 #include <freeradius-devel/util/md4.h>
27 #include <freeradius-devel/util/md5.h>
28 #include <freeradius-devel/util/sha1.h>
29 #include <ctype.h>
30 #include <stdio.h>
31 
32 
33 #include "smbdes.h"
34 
35 static char const hex[] = "0123456789ABCDEF";
36 
37 /*
38  * FIXME: use functions in freeradius
39  */
40 static void tohex (unsigned char const *src, size_t len, char *dst)
41 {
42  size_t i;
43  for (i=0; i<len; i++) {
44  dst[(i*2)] = hex[(src[i] >> 4)];
45  dst[(i*2) + 1] = hex[(src[i]&0x0F)];
46  }
47  dst[(i*2)] = 0;
48 }
49 
50 static void ntpwdhash(uint8_t *out, char const *password)
51 {
52  ssize_t len;
53  uint8_t ucs2_password[512];
54 
55  len = fr_utf8_to_ucs2(ucs2_password, sizeof(ucs2_password), password, strlen(password));
56  if (len < 0) {
57  *out = '\0';
58  return;
59  }
60  fr_md4_calc(out, (uint8_t *) ucs2_password, len);
61 }
62 
63 int main (int argc, char *argv[])
64 {
65  int i, l;
66  char password[1024];
67  uint8_t hash[16];
68  char ntpass[33];
69  char lmpass[33];
70 
71  fprintf(stderr, "LM Hash \tNT Hash\n");
72  fprintf(stderr, "--------------------------------\t--------------------------------\n");
73  fflush(stderr);
74  for (i = 1; i < argc; i++ ) {
75  strlcpy(password, argv[i], sizeof(password));
76  l = strlen(password);
77  if (l && password[l-1] == '\n') password [l-1] = 0;
78  smbdes_lmpwdhash(password, hash);
79  tohex (hash, 16, lmpass);
80  ntpwdhash (hash, password);
81  tohex (hash, 16, ntpass);
82  printf("%s\t%s\n", lmpass, ntpass);
83  }
84  return 0;
85 }
#define RCSID(id)
Definition: build.h:481
void fr_md4_calc(uint8_t out[static MD4_DIGEST_LENGTH], uint8_t const *in, size_t inlen)
Calculate the MD4 hash of the contents of a buffer.
Definition: md4.c:482
long int ssize_t
Definition: merged_model.c:24
unsigned char uint8_t
Definition: merged_model.c:30
ssize_t fr_utf8_to_ucs2(uint8_t *out, size_t outlen, char const *in, size_t inlen)
Convert UTF8 string to UCS2 encoding.
Definition: misc.c:315
static unsigned int hash(char const *username, unsigned int tablesize)
Definition: rlm_passwd.c:132
void smbdes_lmpwdhash(char const *password, uint8_t *lmhash)
Definition: smbdes.c:319
int main(int argc, char *argv[])
Definition: smbencrypt.c:63
static char const hex[]
Definition: smbencrypt.c:35
static void ntpwdhash(uint8_t *out, char const *password)
Definition: smbencrypt.c:50
static void tohex(unsigned char const *src, size_t len, char *dst)
Definition: smbencrypt.c:40
size_t strlcpy(char *dst, char const *src, size_t siz)
Definition: strlcpy.c:34
static size_t char ** out
Definition: value.h:997