Debian Codegraph @

src/core/nteight.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 #include <ctype.h>
34
35 #include "nteight.h"
36 #include "table.h"
37 #include "hash.h"
38 #include "ophel.h"
39 #include "original.h"
40 #include "lmtable.h"
41
42 static uint64_t nteight_sizes[18] = { 8, 67108864, 6000043318LLU, 12000086636LLU, 6000073034LLU, 12000146068LLU, 6000106106LLU, 12000212212LLU, 6000192456LLU, 12000384912LLU, 6000173996LLU, 12000347992LLU, 6000174818LLU, 12000349636LLU, 6000123556LLU, 12000247112LLU, 6000124550LLU, 12000249100LLU};
43 /*-------------------------------------------------------------------------*/
44 int nteight_setup(void *tbl_) {
45 table_t *tbl = tbl_;
46
47 tbl->ncols = 55000;
48 tbl->offset = 100000;
49 tbl->sizes = nteight_sizes;
50
51 tbl->find = nteight_find;
52 tbl->check = nteight_check;
53 tbl->isvalid = nteight_isvalid;
54
55 tbl->lookup_idx = lmtable_lookup_idx;
56 tbl->lookup_end = lmtable_lookup_end;
57 tbl->lookup_srt = nteight_lookup_srt;
58
59 return 1;
60 }
61 /*-------------------------------------------------------------------------*/
62 void nteight_find(void *hsh_, void *tbl_, void *el_) {
63 hash_t *hsh = hsh_;
64 table_t *tbl = tbl_;
65 ophel_t *el = el_;
66 uchar_t *hash = hsh->hash;
67 uchar_t *pwd = (uchar_t*)el->pwd;
68 ophstat_t *stat = el->stat;
69
70 int c;
71 int col = el->col;
72 int ncols = tbl->ncols;
73 int n_redux = col + tbl->idx * tbl->offset;
74
75 uchar_t tmp[16];
76
77 /* Hash and redux until the last column. */
78
79 nteight_mkredux(tbl, hash, pwd, n_redux);
80
81 for (c=1; c<ncols-col; ++c) {
82 ++n_redux;
83
84 nteight_mkhash(pwd, tmp);
85 nteight_mkredux(tbl, tmp, pwd, n_redux);
86 ++stat->hredux;
87 }
88
89 /* Compute the prefix and postfix. */
90
91 uint32_t prefix = nteight_bin64(pwd, 4);
92 uint16_t postfix = (uint16_t)nteight_bin64(pwd+4, 4);
93
94 el->prefix = prefix;
95 el->postfix = postfix;
96 }
97 /*-------------------------------------------------------------------------*/
98 int nteight_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[6] = 0;
134 pwd[7] = 0;
135 pwd[8] = 0;
136 pwd[9] = 0;
137
138 nteight_unbin64(start, pwd, 6);
139
140 return 1;
141 }
142 /*-------------------------------------------------------------------------*/
143 int nteight_check(void *hsh_, void *tbl_, void *el_) {
144 hash_t *hsh = hsh_;
145 table_t *tbl = tbl_;
146 ophel_t *el = el_;
147 uchar_t *hash = hsh->hash;
148 uchar_t *pwd = (uchar_t*)el->pwd;
149 ophstat_t *stat = el->stat;
150
151 int c;
152 int col = el->col;
153 int ncols = tbl->ncols;
154 int n_redux = tbl->idx * tbl->offset;
155
156 uchar_t tmp[16];
157
158 /* Hash and redux until the starting column. */
159
160 stat->falarm_hredux = 0;
161
162 for (c=ncols-col; c<ncols; ++c) {
163 nteight_mkhash(pwd, tmp);
164 nteight_mkredux(tbl, tmp, pwd, n_redux);
165
166 ++n_redux;
167 ++stat->hredux;
168 ++stat->falarm_hredux;
169 }
170
171 /* Check if we got the same hash. */
172
173 nteight_mkhash(pwd, tmp);
174
175 if (memcmp(tmp, hash, sizeof(tmp)) == 0) {
176 ++stat->match_table;
177 stat->falarm_hredux = 0;
178 return 1;
179 }
180
181 else {
182 ++stat->falarm;
183 return 0;
184 }
185 }
186 /*-------------------------------------------------------------------------*/
187 int nteight_isvalid(void *hsh_, void *tbl_) {
188 hash_t *hsh = hsh_;
189
190 return hsh->kind == nt ? 1 : 0;
191 }
192 /*-------------------------------------------------------------------------*/
193 void nteight_mkredux(table_t *tbl, uchar_t *hash, uchar_t *pwd,
194 int n_redux) {
195
196 /* Convert the hash to four unsigned 32-bit integers. */
197
198 uint32_t idx[8];
199 uint32_t un_redux = (uint32_t) n_redux;
200
201 idx[0] = ftohl(*(uint32_t*)hash) ^ un_redux;
202 idx[2] = ftohl(*(uint32_t*)(hash+4)) ^ (un_redux >> 12);
203 idx[4] = ftohl(*(uint32_t*)(hash+8)) ^ (un_redux >> 24);
204 idx[6] = ftohl(*(uint32_t*)(hash+12));
205
206 /* Compute the password */
207
208 idx[1] = idx[0] & 0x3f;
209 idx[0] = (idx[0] >> 6) & 0x3f;
210 idx[3] = idx[2] & 0x3f;
211 idx[2] = (idx[2] >> 6) & 0x3f;
212 idx[5] = idx[4] & 0x3f;
213 idx[4] = (idx[4] >> 6) & 0x3f;
214 idx[7] = idx[6] & 0x3f;
215 idx[6] = (idx[6] >> 6) & 0x3f;
216
217 pwd[0] = nteight_alphanum64[idx[0]];
218 pwd[1] = nteight_alphanum64[idx[1]];
219 pwd[2] = nteight_alphanum64[idx[2]];
220 pwd[3] = nteight_alphanum64[idx[3]];
221 pwd[4] = nteight_alphanum64[idx[4]];
222 pwd[5] = nteight_alphanum64[idx[5]];
223 pwd[6] = nteight_alphanum64[idx[6]];
224 pwd[7] = nteight_alphanum64[idx[7]];
225 pwd[8] = 0;
226
227 }
228 /*-------------------------------------------------------------------------*/
229 void nteight_mkhash(uchar_t *pwd, uchar_t *hash) {
230 make_nthash((char*)pwd, (char*)hash);
231 }
232 /*-------------------------------------------------------------------------*/
233 uint32_t nteight_bin64(uchar_t *input, int length) {
234
235 uint32_t sum=0;
236 int i = 0;
237
238 for (i=0; i<length; i++) {
239 sum = sum*64 + (uint64_t) (strchr((char*)nteight_alphanum64,input[i]) - (char*)nteight_alphanum64);
240 }
241 return sum;
242 }
243 /*-------------------------------------------------------------------------*/
244 int nteight_unbin64(uint32_t input, uchar_t *output, int length) {
245
246 int i = 0;
247 /* start binarized in inverse order ! */
248
249 for (i=0; i<length; i++) {
250 output[i]=nteight_alphanum64[input%64];
251 input/=64;
252 }
253 return 1;
254 }