Debian Codegraph @

src/core/original.c

raw symbols SCIP
1 /*
2 *
3 * Ophcrack is a Lanmanager/NTLM hash cracker based on the faster time-memory
4 * trade-off using rainbow tables.
5 *
6 * Created with the help of: Maxime Mueller, Luca Wullschleger, Claude
7 * Hochreutiner, Andreas Huber and Etienne Dysli.
8 *
9 * Copyright (c) 2008 Philippe Oechslin, Cedric Tissieres, Bertrand Mesot
10 *
11 * Ophcrack is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
15 *
16 * Ophcrack is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
20 *
21 * You should have received a copy of the GNU General Public License
22 * along with Ophcrack; if not, write to the Free Software
23 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 *
25 * This program is released under the GPL with the additional exemption
26 * that compiling, linking, and/or using OpenSSL is allowed.
27 *
28 *
29 *
30 *
31 */
32 #include <stdio.h>
33 #include <string.h>
34 #include <stdlib.h>
35 #include <unistd.h>
36 #include <openssl/md4.h>
37
38 #ifndef WIN32
39 #include <netinet/in.h>
40 #else
41 #include <winsock.h>
42 #endif
43
44 #include "original.h"
45 #include "misc.h"
46 #include "hash.h"
47 /*-------------------------------------------------------------------------*/
48 int resolve_nt_hash(char p1[], char p2[], char h[], unsigned char pw[],
49 int insist) {
50
51 unsigned int i,j, combinations;
52 unsigned int l, max = 0;
53 unsigned char md4[17],*p, orig[15]={0};
54
55 static unsigned char is_multi[256]={
56 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
57 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
58 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
59 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
60 1, 8, 2, 2, 2, 8, 2, 2, 2, 8, 2, 2, 2, 2, 2, 8,
61 2, 2, 2, 2, 2, 8, 2, 2, 2, 2, 2, 1, 1, 1, 1, 1,
62 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
63 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
64
65 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
66 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
67 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
68 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
69 1, 1, 1, 1, 2, 1, 1, 2, 1, 2, 1, 1, 1, 1, 1, 1,
70 1, 2, 1, 1, 1, 1, 2, 1, 1, 1, 1, 1, 2, 1, 1, 1,
71 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
72 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1};
73
74 static unsigned char multi_char[256][12]= {
75 {0}, {0}, {0}, {0}, {0}, {0}, {0}, {0}, {0}, {0}, {0}, {0}, {0}, {0}, {0}, {0},
76 {0}, {0}, {0}, {0}, {0}, {0}, {0}, {0}, {0}, {0}, {0}, {0}, {0}, {0}, {0}, {0},
77 {0}, {0}, {0}, {0}, {0}, {0}, {0}, {0}, {0}, {0}, {0}, {0}, {0}, {0}, {0}, {0},
78 {0}, {0}, {0}, {0}, {0}, {0}, {0}, {0}, {0}, {0}, {0}, {0}, {0}, {0}, {0}, {0},
79 {0}, {'A','a',0xe0,0xe2,0xc0,0xc2,0xe3,0xc3}, "Bb", "Cc", "Dd",
80 {'E','e',0xc8,0xe8,0xca,0xea,0xeb,0xcb}, "Ff", "Gg", "Hh", {'I','i',0xee,0xef,0xce,0xcf,0xed,0xcd},
81 "Jj", "Kk", "Ll", "Mm", "Nn", {'O','o',0xf4,0xd4,0xf3,0xf5,0xd3,0xd5},
82 "Pp", "Qq", "Rr", "Ss", "Tt", {'U','u',0xf9,0xfb,0xd9,0xdb,0xfa,0xda}, "Vv",
83 "Ww", "Xx", "Yy", "Zz", {0}, {0}, {0}, {0}, {0},
84 {0}, {0}, {0}, {0}, {0}, {0}, {0}, {0}, {0}, {0}, {0}, {0}, {0}, {0}, {0}, {0},
85 {0}, {0}, {0}, {0}, {0}, {0}, {0}, {0}, {0}, {0}, {0}, {0}, {0}, {0}, {0}, {0},
86
87 {0}, {0}, {0}, {0}, {0}, {0}, {0}, {0}, {0}, {0}, {0}, {0}, {0}, {0}, {0}, {0},
88 {0}, {0}, {0}, {0}, {0}, {0}, {0}, {0}, {0}, {0}, {0}, {0}, {0}, {0}, {0}, {0},
89 {0}, {0}, {0}, {0}, {0}, {0}, {0}, {0}, {0}, {0}, {0}, {0}, {0}, {0}, {0}, {0},
90 {0}, {0}, {0}, {0}, {0}, {0}, {0}, {0}, {0}, {0}, {0}, {0}, {0}, {0}, {0}, {0},
91 {0}, {0}, {0}, {0}, {0xc4,0xe4}, {0}, {0}, {0xe7,0xc7}, {0}, {0xc9,0xe9}, {0}, {0}, {0}, {0}, {0}, {0},
92 {0}, {0xd1,0xf1}, {0}, {0}, {0}, {0}, {0xd6,0xf6}, {0}, {0}, {0}, {0}, {0}, {0xdc,0xfc}, {0}, {0}, {0xdf},
93 {0}, {0}, {0}, {0}, {0}, {0}, {0}, {0}, {0}, {0}, {0}, {0}, {0}, {0}, {0}, {0},
94 {0}, {0}, {0}, {0}, {0}, {0}, {0}, {0}, {0}, {0}, {0}, {0}, {0}, {0}, {0}, {0}} ;
95
96 static int max_multi=8;
97
98 memset(pw, 0, 16);
99 strcpy((char*)pw,p1);
100 strcpy((char*)(pw+7),p2);
101
102 l=strlen((char*)pw);
103
104 p = (unsigned char *)pw;
105 for (i=0; i<l; i++)
106 if (p[i]>=128)
107 switch(p[i]){
108 case 0x8e: p[i]=0xc4;break; // capital a umlaut
109 case 0x99: p[i]=0xd6;break; // capital o umlaut
110 case 0x9a: p[i]=0xdc;break; // capital u umlaut
111 case 0xe1: p[i]=0xdf;break; // double s
112 case 0xa5: p[i]=0xd1;break; // capital n tilda
113 case 0x90: p[i]=0xc9;break; // capital e accute
114 case 0x80: p[i]=0xc7;break; // capital c cedilla
115 }
116
117 strcpy((char*)orig, (char*)pw);
118 combinations=1;
119
120 for (i=0; i<l; i++)
121 combinations *=is_multi[pw[i]];
122
123 if (!insist) {
124 max = max_multi;
125 while (combinations > RESOLVE_MAX_COMBINATIONS) {
126 max--;
127 combinations = 1;
128 for (i=0; i<l; i++)
129 combinations *= MY_MIN(is_multi[pw[i]],max);
130 }
131 }
132
133 for (i=0; i<combinations; i++) {
134 int c,m;
135 c=i;
136
137 for (j=0; j<l; j++) {
138 m = MY_MIN(is_multi[orig[j]],max);
139 pw[j]=((m>1) ? multi_char[orig[j]][c%m]:orig[j]);
140 c/=m;
141 }
142 md4[16]=0;
143 make_nthash((char*)pw, (char*)md4);
144
145 if (!memcmp(md4,h,16))
146 return 1;
147 }
148
149 memset(pw, 0, 16);
150 return 0;
151 }
152 /*-------------------------------------------------------------------------*/
153 void make_nthash(char *pw, char *out) {
154 uchar_t *pwd = (uchar_t*)pw;
155
156 /* Convert to unicode. */
157
158 uint16_t unipwd[128] = {0};
159 int len = strlen(pw);
160 int i;
161
162 for (i=0; i<len; ++i)
163 unipwd[i] = htons(pwd[i] << 8);
164
165 /* Compute MD4 of Unicode password. */
166
167 MD4_CTX ctx;
168
169 MD4_Init(&ctx);
170 MD4_Update(&ctx, unipwd, len * sizeof(uint16_t));
171 MD4_Final((uchar_t*)out, &ctx);
172 }