Debian Codegraph @

src/core/ntnine.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 "ntnine.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 ntnine_sizes[14] = { 6, 241864704, 2963172506, 5926345012LLU, 2963141176, 5926282352LLU, 2963198436, 5926396872LLU, 2963189836, 5926379672LLU, 2963140476, 5926280952LLU, 2963169516, 5926339032LLU};
43 /*-------------------------------------------------------------------------*/
44 int ntnine_setup(void *tbl_) {
45 table_t *tbl = tbl_;
46
47 tbl->ncols = 45000;
48 tbl->offset = 50000;
49 tbl->sizes = ntnine_sizes;
50
51 tbl->find = ntnine_find;
52 tbl->check = ntnine_check;
53 tbl->isvalid = ntnine_isvalid;
54
55 tbl->lookup_idx = lmtable_lookup_idx;
56 tbl->lookup_end = lmtable_lookup_end;
57 tbl->lookup_srt = ntnine_lookup_srt;
58
59 return 1;
60 }
61 /*-------------------------------------------------------------------------*/
62 void ntnine_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 ntnine_mkredux(tbl, hash, pwd, n_redux);
80
81 for (c=1; c<ncols-col; ++c) {
82 ++n_redux;
83
84 ntnine_mkhash(pwd, tmp);
85 ntnine_mkredux(tbl, tmp, pwd, n_redux);
86 ++stat->hredux;
87 }
88
89 /* Compute the prefix and postfix. */
90
91 uint32_t prefix = ntnine_bin36(pwd, 5);
92 uint16_t postfix = (uint16_t)ntnine_bin37(pwd+5, 4);
93
94 el->prefix = prefix;
95 el->postfix = postfix;
96 }
97 /*-------------------------------------------------------------------------*/
98 int ntnine_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 ntnine_unbin36(start, pwd, 6);
139
140 return 1;
141 }
142 /*-------------------------------------------------------------------------*/
143 int ntnine_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 ntnine_mkhash(pwd, tmp);
164 ntnine_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 ntnine_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 ntnine_isvalid(void *hsh_, void *tbl_) {
188 hash_t *hsh = hsh_;
189
190 return hsh->kind == nt ? 1 : 0;
191 }
192 /*-------------------------------------------------------------------------*/
193 void ntnine_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[6];
199
200 idx[0] = ftohl(*(uint32_t*)hash) ^ n_redux;
201 idx[2] = ftohl(*(uint32_t*)(hash+4));
202 idx[4] = ftohl(*(uint32_t*)(hash+8));
203 idx[5] = ftohl(*(uint32_t*)(hash+12));
204
205 int i;
206
207 /* Compute the password */
208
209 idx[1] = idx[0] % power2_36;
210 idx[0] /= power2_36;
211 idx[0] %= power2_36;
212
213 idx[3] = idx[2] % power2_36;
214 idx[2] /= power2_36;
215 idx[2] %= power2_36;
216
217 pwd[0] = ntnine_low36[idx[0]/36];
218 pwd[1] = ntnine_low36[idx[0]%36];
219 pwd[2] = ntnine_low36[idx[1]/36];
220 pwd[3] = ntnine_low36[idx[1]%36];
221 pwd[4] = ntnine_low36[idx[2]/36];
222 pwd[5] = ntnine_low36[idx[2]%36];
223 pwd[6] = ntnine_low36[idx[3]/36];
224 pwd[7] = ntnine_low36[idx[3]%36];
225
226 /* Finish the password. */
227
228
229 if (idx[5] > max8) {
230 idx[4] %= power2_36;
231 pwd[8] = ntnine_low36[idx[4]/36];
232 pwd[9] = 0;
233 } else {
234 pwd[8] = 0;
235 for (i=0; i<8; i++)
236 if (pwd[i] > 0x60) {
237 pwd[i] -= 0x20;
238 break;
239 }
240 }
241 }
242 /*-------------------------------------------------------------------------*/
243 void ntnine_mkhash(uchar_t *pwd, uchar_t *hash) {
244 make_nthash((char*)pwd, (char*)hash);
245 }
246 /*-------------------------------------------------------------------------*/
247 uint32_t ntnine_bin36(uchar_t *input, int length) {
248
249 uint32_t sum=0;
250 int i = 0;
251
252 for (i=0; i<length; i++) {
253 sum = sum*36 + (uint64_t) (strchr((char*)ntnine_low36,tolower(input[i])) - (char*)ntnine_low36);
254 }
255 return sum;
256 }
257 /*-------------------------------------------------------------------------*/
258 uint32_t ntnine_bin37(uchar_t *input, int length) {
259
260 uint32_t sum=0;
261 int i = 0;
262
263 for (i=0; i<length; i++) {
264 if (input[i]==0)
265 sum = sum*37;
266 else
267 sum = sum*37+ 1 + (uint64_t) (strchr((char*)ntnine_low36,input[i]) - (char*)ntnine_low36);
268 }
269 return sum;
270 }
271 /*-------------------------------------------------------------------------*/
272 int ntnine_unbin36(uint32_t input, uchar_t *output, int length) {
273
274 int i = 0;
275
276 for (i=length-1; i>=0; i--) {
277 output[i]=ntnine_low36[input%36];
278 input/=36;
279 }
280 return 1;
281 }