-
Notifications
You must be signed in to change notification settings - Fork 190
/
Copy pathutils.cu
executable file
·330 lines (273 loc) · 8.95 KB
/
utils.cu
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
/*
* BitCracker: BitLocker password cracking tool, CUDA version.
* Copyright (C) 2013-2017 Elena Ago <elena dot ago at gmail dot com>
* Massimo Bernaschi <massimo dot bernaschi at gmail dot com>
*
* This file is part of the BitCracker project: https://github.com/e-ago/bitcracker
*
* BitCracker is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2 of the License, or
* (at your option) any later version.
*
* BitCracker is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with BitCracker. If not, see <http://www.gnu.org/licenses/>.
*/
#include "bitcracker.h"
/* John The Ripper function */
char *strtokm(char *s1, const char *delims)
{
static char *last = NULL;
char *endp;
if (!s1)
s1 = last;
if (!s1 || *s1 == 0)
return last = NULL;
endp = strpbrk(s1, delims);
if (endp) {
*endp = '\0';
last = endp + 1;
} else
last = NULL;
return s1;
}
void * Calloc(size_t len, size_t size) {
void * ptr = NULL;
if( size <= 0)
{
fprintf(stderr,"Critical error: memory size is 0\n");
exit(EXIT_FAILURE);
}
ptr = (void *)calloc(len, size);
if( ptr == NULL )
{
fprintf(stderr,"Critical error: Memory allocation\n");
exit(EXIT_FAILURE);
}
return ptr;
}
void fillBuffer(FILE *fp, unsigned char *buffer, int size)
{
int k;
for (k = 0; k < size; k++)
buffer[k] = (unsigned char)fgetc(fp);
}
void print_hex(unsigned char *str, int len)
{
int i;
for (i = 0; i < len; ++i)
printf("%02x", str[i]);
printf("\n");
}
int parse_data(char *input_hash, unsigned char ** salt, unsigned char ** nonce, unsigned char ** vmk, unsigned char ** mac)
{
char * hash;
char *p;
int i, salt_size, iterations, vmk_size, nonce_size;
FILE * fphash;
char tmp[2];
int j=0, auth_method=0;
const char zero_string[17]="0000000000000000";
(*salt) = (unsigned char *) Calloc(SALT_SIZE, sizeof(unsigned char));
(*nonce) = (unsigned char *) Calloc(NONCE_SIZE, sizeof(unsigned char));
(*vmk) = (unsigned char *) Calloc(VMK_SIZE, sizeof(unsigned char));
(*mac) = (unsigned char *) Calloc(MAC_SIZE, sizeof(unsigned char));
hash = (char *) Calloc(INPUT_HASH_SIZE, sizeof(char));
if(!input_hash)
{
fprintf(stderr, "No input hash provided\n");
goto out;
}
fphash = fopen(input_hash, "r");
if (!fphash) {
fprintf(stderr, "! %s : %s\n", input_hash, strerror(errno));
goto out;
}
fgets(hash, INPUT_HASH_SIZE, fphash);
if(!hash)
{
fprintf(stderr, "No correct input hash provided\n");
goto out;
}
printf("Reading hash file \"%s\"\n%s", input_hash, hash);
if (strncmp(hash, HASH_TAG, HASH_TAG_LEN) != 0)
{
fprintf(stderr, "Wrong hash format\n");
goto out;
}
hash += HASH_TAG_LEN;
p = strtokm(hash, "$"); // version
//take care of all the possible errors
auth_method = atoi(p);
if( (auth_method == 0 || auth_method == 1) && attack_mode == MODE_RECV_PASS)
{
fprintf(stderr, "Input Hash error: you choose the -r option (Recovery Password) but the input hash MUST be used with -u option (User Password).\n");
goto out;
}
else if(auth_method == 2 && attack_mode == MODE_USER_PASS)
{
fprintf(stderr, "Input Hash error: you choose the -u option (User Password) but the input hash MUST be used with -r option (Recovery Password).\n");
goto out;
}
p = strtokm(NULL, "$"); // salt length
salt_size = atoi(p);
if(salt_size != SALT_SIZE)
{
fprintf(stderr, "Wrong Salt size\n");
goto out;
}
p = strtokm(NULL, "$"); // salt
for (i = 0, j = 0; i < salt_size*2; i+=2, j++)
{
(*salt)[j] = (p[i] <= '9' ? p[i] - '0' : toupper(p[i]) - 'A' + 10) << 4;
(*salt)[j] |= p[i+1] <= '9' ? p[i+1] - '0' : toupper(p[i+1]) - 'A' + 10;
}
p = strtokm(NULL, "$"); // iterations
iterations = atoi(p);
if(iterations != ITERATION_NUMBER)
{
fprintf(stderr, "Wrong Iterations parameter\n");
goto out;
}
p = strtokm(NULL, "$"); // nonce length
nonce_size = atoi(p);
if(nonce_size != NONCE_SIZE)
{
fprintf(stderr, "Wrong Nonce size\n");
goto out;
}
p = strtokm(NULL, "$"); // nonce
for (i = 0, j = 0; i < nonce_size*2; i+=2, j++)
{
(*nonce)[j] = (p[i] <= '9' ? p[i] - '0' : toupper(p[i]) - 'A' + 10) << 4;
(*nonce)[j] |= p[i+1] <= '9' ? p[i+1] - '0' : toupper(p[i+1]) - 'A' + 10;
}
p = strtokm(NULL, "$"); // data_size
vmk_size = atoi(p);
if(vmk_size != VMK_SIZE)
{
fprintf(stderr, "Wrong VMK size\n");
goto out;
}
p = strtokm(NULL, "$"); // data
for (i = 0, j = 0; i < MAC_SIZE*2; i+=2, j++)
{
(*mac)[j] = (p[i] <= '9' ? p[i] - '0' : toupper(p[i]) - 'A' + 10) << 4;
(*mac)[j] |= p[i+1] <= '9' ? p[i+1] - '0' : toupper(p[i+1]) - 'A' + 10; }
if(mac_comparison == 1 && !memcmp((*mac), zero_string, MAC_SIZE))
{
free(*mac);
(*mac)=NULL;
}
for (j=0; i < vmk_size*2; i+=2, j++)
{
(*vmk)[j] = (p[i] <= '9' ? p[i] - '0' : toupper(p[i]) - 'A' + 10) << 4;
(*vmk)[j] |= p[i+1] <= '9' ? p[i+1] - '0' : toupper(p[i+1]) - 'A' + 10;
}
fclose(fphash);
return BIT_SUCCESS;
out:
fclose(fphash);
free(*salt);
free(*nonce);
free(*vmk);
free(*mac);
return BIT_FAILURE;
}
static int print_once=0;
int readFilePassword(uint32_t ** buf_i, char ** buf_c, int maxNumPsw, FILE *fp) {
int i=0, j=0, k=0, size=0, count=0;
char tmp[PSW_CHAR_SIZE], tmp2[PSW_CHAR_SIZE], *p;
memset(tmp, 0, PSW_CHAR_SIZE);
if (fp == NULL || feof(fp) || buf_i == NULL)
return -1;
while(fgets(tmp, PSW_CHAR_SIZE, fp)) {
j=0; k=0; count=0;
size = (strlen(tmp)-1);
if(attack_mode == MODE_USER_PASS && ( size > SECOND_LENGHT || size < MIN_INPUT_PASSWORD_LEN) && print_once == 0)
{
fprintf(stderr, "WARNING: During USER PASSWORD attack, only passwords between %d and %d character are considered. Passwords like %s will be ignored.\n", MIN_INPUT_PASSWORD_LEN, SECOND_LENGHT, tmp);
print_once=1;
}
if(tmp[0] == '\n' || size < MIN_INPUT_PASSWORD_LEN || size > SECOND_LENGHT)
continue;
memcpy(( (*buf_c)+(i*PSW_CHAR_SIZE)), tmp, size);
if(attack_mode == MODE_RECV_PASS) //Recovery password
{
memset(tmp2, 0, PSW_CHAR_SIZE);
p = strtokm(tmp, "-");
do
{
//Dislocker, Recovery Password checks
if( ((atoi(p) % 11) != 0) || (atoi(p) >= 720896) ) break;
int8_t check_digit = (int8_t) ( p[0] - p[1] + p[2] - p[3] + p[4] - 48 ) % 11;
if( check_digit < 0 ) check_digit = (int8_t) check_digit + 11;
if( check_digit != (p[5] - 48)) break;
((uint16_t*)(tmp2+count))[0] = (uint16_t)(atoi(p) / 11);
p = strtokm(NULL, "-");
count+=2;
} while(p != NULL);
if(count != (RECOVERY_PASS_BLOCKS*2)) continue;
((*buf_i)+(i*PSW_INT_SIZE))[0] = ( (((uint32_t)tmp2[0] ) << 24) & 0xFF000000) |
( (((uint32_t)tmp2[0+1]) << 16) & 0x00FF0000) |
( (((uint32_t)tmp2[0+2]) << 8) & 0x0000FF00) |
( (((uint32_t)tmp2[0+3]) << 0) & 0x000000FF);
((*buf_i)+(i*PSW_INT_SIZE))[1] = ( (((uint32_t)tmp2[4]) << 24) & 0xFF000000) |
( (((uint32_t)tmp2[4+1]) << 16) & 0x00FF0000) |
( (((uint32_t)tmp2[4+2]) << 8) & 0x0000FF00) |
( (((uint32_t)tmp2[4+3]) << 0) & 0x000000FF);
((*buf_i)+(i*PSW_INT_SIZE))[2] = ( (((uint32_t)tmp2[8]) << 24) & 0xFF000000) |
( (((uint32_t)tmp2[8+1]) << 16) & 0x00FF0000) |
( (((uint32_t)tmp2[8+2]) << 8) & 0x0000FF00) |
( (((uint32_t)tmp2[8+3]) << 0) & 0x000000FF);
((*buf_i)+(i*PSW_INT_SIZE))[3] = ( (((uint32_t)tmp2[12]) << 24) & 0xFF000000) |
( (((uint32_t)tmp2[12+1]) << 16) & 0x00FF0000) |
( (((uint32_t)tmp2[12+2]) << 8) & 0x0000FF00) |
( (((uint32_t)tmp2[12+3]) << 0) & 0x000000FF);
((*buf_i)+(i*PSW_INT_SIZE))[4] = 0x80000000;
((*buf_i)+(i*PSW_INT_SIZE))[5] = 0;
((*buf_i)+(i*PSW_INT_SIZE))[6] = 0;
((*buf_i)+(i*PSW_INT_SIZE))[7] = 0;
((*buf_i)+(i*PSW_INT_SIZE))[8] = 0;
((*buf_i)+(i*PSW_INT_SIZE))[9] = 0;
((*buf_i)+(i*PSW_INT_SIZE))[10] = 0;
((*buf_i)+(i*PSW_INT_SIZE))[11] = 0;
((*buf_i)+(i*PSW_INT_SIZE))[12] = 0;
((*buf_i)+(i*PSW_INT_SIZE))[13] = 0;
((*buf_i)+(i*PSW_INT_SIZE))[14] = 0;
((*buf_i)+(i*PSW_INT_SIZE))[15] = 0x80;
}
else //User Password
{
tmp[size] = 0x80;
do
{
((*buf_i)+(i*PSW_INT_SIZE)+j)[0] = ( (((uint32_t)tmp[k]) << 24) & 0xFF000000);
k++;
if(k <= size)
((*buf_i)+(i*PSW_INT_SIZE)+j)[0] = ((*buf_i)+(i*PSW_INT_SIZE)+j)[0] | ( (((uint32_t)tmp[k]) << 8) & 0x0000FF00);
j++;
k++;
} while(k <= size);
if(size <= FIRST_LENGHT)
{
((*buf_i)+(i*PSW_INT_SIZE)+14)[0] = 0xFFFFFFFF;
((*buf_i)+(i*PSW_INT_SIZE)+15)[0] = ((uint8_t)(((size*2) << 3) >> 8)) << 8 | ((uint8_t)((size*2) << 3));
}
else
{
((*buf_i)+(i*PSW_INT_SIZE)+30)[0] = 0;
((*buf_i)+(i*PSW_INT_SIZE)+31)[0] = ((uint8_t)(((size*2) << 3) >> 8)) << 8 | ((uint8_t)((size*2) << 3));
}
}
memset(tmp, 0, PSW_CHAR_SIZE);
i++;
if(i >= maxNumPsw) break;
}
return i;
}