Debian Codegraph @

src/core/ntextended.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 <string.h>
33
34 #include "ntextended.h"
35 #include "table.h"
36 #include "hash.h"
37 #include "ophel.h"
38 #include "original.h"
39 #include "lmtable.h"
40
41 static uint64_t ntextended_sizes[10] = { 4, 108118236, 672425284, 1344850568, 672442590, 1344885180, 672411252, 1344822504, 672417770, 1344835540};
42 /*-------------------------------------------------------------------------*/
43 int ntextended_setup(void *tbl_) {
44 table_t *tbl = tbl_;
45
46 tbl->ncols = 24320;
47 tbl->offset = 50000;
48 tbl->sizes = ntextended_sizes;
49
50 tbl->find = ntextended_find;
51 tbl->check = ntextended_check;
52 tbl->isvalid = ntextended_isvalid;
53
54 tbl->lookup_idx = lmtable_lookup_idx;
55 tbl->lookup_end = lmtable_lookup_end;
56 tbl->lookup_srt = ntextended_lookup_srt;
57
58 return 1;
59 }
60 /*-------------------------------------------------------------------------*/
61 void ntextended_find(void *hsh_, void *tbl_, void *el_) {
62 hash_t *hsh = hsh_;
63 table_t *tbl = tbl_;
64 ophel_t *el = el_;
65 uchar_t *hash = hsh->hash;
66 uchar_t *pwd = (uchar_t*)el->pwd;
67 ophstat_t *stat = el->stat;
68
69 int c;
70 int col = el->col;
71 int ncols = tbl->ncols;
72 int n_redux = col + tbl->idx * tbl->offset;
73
74 uchar_t tmp[16];
75
76 /* Hash and redux until the last column. */
77
78 ntextended_mkredux(tbl, hash, pwd, n_redux);
79
80 for (c=1; c<ncols-col; ++c) {
81 ++n_redux;
82
83 ntextended_mkhash(pwd, tmp);
84 ntextended_mkredux(tbl, tmp, pwd, n_redux);
85 ++stat->hredux;
86 }
87
88 /* Compute the prefix and postfix. */
89
90 uint64_t pw_bin = ntextended_bin43(pwd);
91 uint32_t prefix = (uint32_t)(pw_bin >> 18 & 0x00000000FFFFFFFF);
92 uint16_t postfix = (uint16_t)(pw_bin & 0x000000000000FFFF);
93
94 el->prefix = prefix;
95 el->postfix = postfix;
96 }
97 /*-------------------------------------------------------------------------*/
98 int ntextended_lookup_srt(void *hsh_, void *tbl_, void *el_) {
99 table_t *tbl = tbl_;
100 ophel_t *el = el_;
101
102 uint64_t offset = el->offset;
103 uint32_t start;
104
105 ophstat_t *stat = el->stat;
106 ++stat->start;
107
108 /* If the .start file has been preloaded, then we look into the memory. */
109
110 if (tbl->srtmem) {
111 uint32_t *mem = (uint32_t*)(tbl->srtmem + offset);
112 start = mem[0];
113 }
114
115 /* Otherwise, we access the disk. */
116
117 else {
118 FILE *srtfile = tbl->srtfile;
119
120 fseeko(srtfile, offset, SEEK_SET);
121 fread(&start, sizeof(start), 1, srtfile);
122 ++stat->fseek_srt;
123 }
124
125 /* Make sure that start is in the correct byte order. */
126
127 start = ftohl(start);
128
129 /* Convert it to a valid password. */
130
131 uchar_t *pwd = (uchar_t*)el->pwd;
132
133 pwd[5] = 0;
134 pwd[6] = 0;
135 pwd[7] = 0;
136
137 ntextended_unbin95(start, pwd);
138
139 return 1;
140 }
141 /*-------------------------------------------------------------------------*/
142 int ntextended_check(void *hsh_, void *tbl_, void *el_) {
143 hash_t *hsh = hsh_;
144 table_t *tbl = tbl_;
145 ophel_t *el = el_;
146 uchar_t *hash = hsh->hash;
147 uchar_t *pwd = (uchar_t*)el->pwd;
148 ophstat_t *stat = el->stat;
149
150 int c;
151 int col = el->col;
152 int ncols = tbl->ncols;
153 int n_redux = tbl->idx * tbl->offset;
154
155 uchar_t tmp[16];
156
157 /* Hash and redux until the starting column. */
158
159 stat->falarm_hredux = 0;
160
161 for (c=ncols-col; c<ncols; ++c) {
162 ntextended_mkhash(pwd, tmp);
163 ntextended_mkredux(tbl, tmp, pwd, n_redux);
164
165 ++n_redux;
166 ++stat->hredux;
167 ++stat->falarm_hredux;
168 }
169
170 /* Check if we got the same hash. */
171
172 ntextended_mkhash(pwd, tmp);
173
174 if (memcmp(tmp, hash, sizeof(tmp)) == 0) {
175 ++stat->match_table;
176 stat->falarm_hredux = 0;
177 return 1;
178 }
179
180 else {
181 ++stat->falarm;
182 return 0;
183 }
184 }
185 /*-------------------------------------------------------------------------*/
186 int ntextended_isvalid(void *hsh_, void *tbl_) {
187 hash_t *hsh = hsh_;
188
189 return hsh->kind == nt ? 1 : 0;
190 }
191 /*-------------------------------------------------------------------------*/
192 void ntextended_mkredux(table_t *tbl, uchar_t *hash, uchar_t *pwd,
193 int n_redux) {
194
195 /* Convert the hash to four unsigned 32-bit integers. */
196
197 uint32_t idx[4];
198
199 idx[0] = ftohl(*(uint32_t*)hash) ^ n_redux;
200 idx[1] = ftohl(*(uint32_t*)(hash+4));
201 idx[2] = ftohl(*(uint32_t*)(hash+8));
202 idx[3] = ftohl(*(uint32_t*)(hash+12));
203
204 int n = idx[3];
205 int i;
206
207 /* Compute the password */
208
209 pwd[8] = 0;
210
211 if (n > ntextended_max[8]) { // 36 chars
212 for (i=0; i<3; ++i) {
213 pwd[i] = ntextended_low36[idx[0] % 36];
214 idx[0] /= 36;
215 }
216
217 for (i=3; i<6; ++i) {
218 pwd[i] = ntextended_low36[idx[1] % 36];
219 idx[1] /= 36;
220 }
221
222 for (i=6; i<8; ++i) {
223 pwd[i] = ntextended_low36[idx[2] % 36];
224 idx[2] /= 36;
225 }
226 } else if (n > ntextended_max[7]) { // 62 chars
227 for (i=0; i<3; ++i) {
228 pwd[i] = ntextended_alphanum62[idx[0] % 62];
229 idx[0] /= 62;
230 }
231
232 for (i=3; i<7; ++i) {
233 pwd[i] = ntextended_alphanum62[idx[1] % 62];
234 idx[1] /= 62;
235 }
236
237 pwd[7] = 0;
238 } else { // 95 chars
239 for (i=0; i<3; ++i) {
240 pwd[i] = ntextended_ext95[idx[0] % 95];
241 idx[0] /= 95;
242 }
243
244 for (i=3; i<6; ++i) {
245 pwd[i] = ntextended_ext95[idx[1] % 95];
246 idx[1] /= 95;
247 }
248
249 /* Truncate the password. */
250
251 pwd[7] = 0;
252 pwd[6] = 0;
253
254 if (n < ntextended_max[6]) {
255 pwd[5]=0;
256 if (n < ntextended_max[5]) {
257 pwd[4]=0;
258 if (n < ntextended_max[4]) {
259 pwd[3]=0;
260 if (n < ntextended_max[3]) {
261 pwd[2]=0;
262 if (n < ntextended_max[2]) {
263 pwd[1]=0;
264 }
265 }
266 }
267 }
268 }
269 }
270 }
271 /*-------------------------------------------------------------------------*/
272 void ntextended_mkhash(uchar_t *pwd, uchar_t *hash) {
273 make_nthash((char*)pwd, (char*)hash);
274 }
275 /*-------------------------------------------------------------------------*/
276 uint64_t ntextended_bin43(uchar_t *input) {
277 int i;
278 int l = (int)strlen((char*)input);
279 uint64_t sum = 0;
280
281 if (l<7)
282 for (i=0; i<l && i<6; i++) {
283 char *x1 = strchr((char*)ntextended_ext95, input[i]);
284 char *x2 = (char*)ntextended_ext95;
285
286 sum = sum*95 + (uint64_t)(x1-x2);
287 }
288
289 else if (l==7)
290 for (i=0; i<7; i++) {
291 char *x1 = strchr((char*)ntextended_alphanum62, input[i]);
292 char *x2 = (char*)ntextended_alphanum62;
293
294 sum = sum*62 + (uint64_t)(x1-x2);
295 }
296
297 else if (l==8)
298 for (i=0; i<8; i++) {
299 char *x1 = strchr((char*)ntextended_low36, input[i]);
300 char *x2 = (char*)ntextended_low36;
301
302 sum = sum*36 + (uint64_t)(x1-x2);
303 }
304
305 sum += ntextended_offset[l-1];
306
307 return sum;
308 }
309 /*-------------------------------------------------------------------------*/
310 void ntextended_unbin95(uint32_t input, uchar_t *output) {
311 int i = 0;
312
313 for (i=4; i>=0; i--) {
314 output[i] = ntextended_ext95[input % 95];
315 input /= 95;
316 }
317 }