Debian Codegraph @

src/core/lmflash.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 <stdint.h>
33 #include <string.h>
34
35 #include "lmflash.h"
36 #include "lmtable.h"
37 #include "hash.h"
38 #include "ophel.h"
39 #include "original.h"
40 #include "misc.h"
41
42 static uint64_t lmflash_sizes[14] = { 6, 268435456, 5279834004ULL, 10559668008ULL, 5279862016ULL, 10559724032ULL, 5279757448ULL, 10559514896ULL, 5279801098ULL, 10559602196ULL, 5279747172ULL, 10559494344ULL, 5279855682ULL, 10559711364ULL};
43 /*-------------------------------------------------------------------------*/
44 int lmflash_setup(void *tbl_) {
45 table_t *tbl = tbl_;
46
47 tbl->ncols = 2200;
48 tbl->offset = 100000;
49 tbl->sizes = lmflash_sizes;
50
51 tbl->find = lmflash_find;
52 tbl->check = lmtable_check;
53 tbl->isvalid = lmtable_isvalid;
54
55 tbl->lookup_idx = lmtable_lookup_idx;
56 tbl->lookup_end = lmtable_lookup_end;
57 tbl->lookup_srt = lmflash_lookup_srt;
58
59 return 1;
60 }
61 /*-------------------------------------------------------------------------*/
62 void lmflash_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[8];
76
77 /* Hash and redux until the last column. */
78
79 lmtable_mkredux(tbl, hash, pwd, n_redux);
80
81 for (c=1; c<ncols-col; ++c) {
82 ++n_redux;
83
84 lmtable_mkhash(pwd, tmp);
85 lmtable_mkredux(tbl, tmp, pwd, n_redux);
86 ++stat->hredux;
87 }
88
89 /* Compute the prefix and postfix. */
90
91 uint64_t pw_bin = lmflash_bin69(pwd);
92 uint32_t prefix = (uint32_t)(pw_bin >> 17 & 0x00000000FFFFFFFF);
93 uint16_t postfix = (uint16_t)(pw_bin & 0x000000000000FFFF);
94
95 el->prefix = prefix;
96 el->postfix = postfix;
97 }
98 /*-------------------------------------------------------------------------*/
99 int lmflash_lookup_srt(void *hsh_, void *tbl_, void *el_) {
100 table_t *tbl = tbl_;
101 ophel_t *el = el_;
102
103 uint64_t offset = el->offset;
104 uint32_t start;
105
106 ophstat_t *stat = el->stat;
107 ++stat->start;
108
109 /* If the .start file has been preloaded, then we look into the memory. */
110
111 if (tbl->srtmem) {
112 uint32_t *mem = (uint32_t*)(tbl->srtmem + offset);
113 start = mem[0];
114 }
115
116 /* Otherwise, we access the disk. */
117
118 else {
119 FILE *srtfile = tbl->srtfile;
120
121 fseeko(srtfile, offset, SEEK_SET);
122 fread(&start, sizeof(start), 1, srtfile);
123 ++stat->fseek_srt;
124 }
125
126 /* Make sure that start is in the correct byte order. */
127
128 start = ftohl(start);
129
130 /* Convert it to a valid password. */
131
132 uchar_t *pwd = (uchar_t*)el->pwd;
133
134 memset(pwd, 0, 8);
135
136 lmflash_unbin69(start, pwd);
137
138 return 1;
139 }
140 /*-------------------------------------------------------------------------*/
141 uint64_t lmflash_bin69(uchar_t *input) {
142 int i = 0;
143 uint64_t sum = 0;
144 uint64_t offset = 7446353252589ULL;
145
146 for (i=0; i<7; i++) {
147 if (input[i]) {
148 char *x1 = (char*)memchr(extended_chars, input[i], 73);
149 char *x2 = (char*)extended_chars;
150
151 sum = sum*69 + (uint64_t)(x1-x2);
152 } else {
153 sum += offset;
154 offset /= 69;
155 }
156 }
157
158 return sum;
159 }
160 /*-------------------------------------------------------------------------*/
161 void lmflash_unbin69(uint32_t input, uchar_t *output) {
162 int i = 0;
163
164 for (i=5; i>=0; i--) {
165 output[i] = extended_chars[input % 69];
166 input /= 69;
167 }
168 }