1 /**
2 * Author......: See docs/credits.txt
3 * License.....: MIT
4 */
5
6 #include "common.h"
7 #include "types.h"
8 #include "modules.h"
9 #include "bitops.h"
10 #include "convert.h"
11 #include "shared.h"
12 #include "memory.h"
13 #include "cpu_crc32.h"
14 #include "keyboard_layout.h"
15
16 static const u32 ATTACK_EXEC = ATTACK_EXEC_OUTSIDE_KERNEL;
17 static const u32 DGST_POS0 = 0;
18 static const u32 DGST_POS1 = 1;
19 static const u32 DGST_POS2 = 2;
20 static const u32 DGST_POS3 = 3;
21 static const u32 DGST_SIZE = DGST_SIZE_8_8;
22 static const u32 HASH_CATEGORY = HASH_CATEGORY_FDE;
23 static const char *HASH_NAME = "TrueCrypt SHA512 + XTS 1024 bit";
24 static const u64 KERN_TYPE = 6222;
25 static const u32 OPTI_TYPE = OPTI_TYPE_ZERO_BYTE
26 | OPTI_TYPE_SLOW_HASH_SIMD_LOOP
27 | OPTI_TYPE_USES_BITS_64;
28 static const u64 OPTS_TYPE = OPTS_TYPE_PT_GENERATE_LE
29 | OPTS_TYPE_BINARY_HASHFILE
30 | OPTS_TYPE_MAXIMUM_THREADS;
31 static const u32 SALT_TYPE = SALT_TYPE_EMBEDDED;
32 static const char *ST_PASS = "hashcat";
33 static const char *ST_HASH = "9f207bec0eded18a1b2e324d4f05d2f33f0bd1aeb43db65d33242fa48ac960fad4c14d04c553e06ad47e7e394d16e0a6544d35fb0b2415bd060bc5f537e42a58b1681e991e2ec0b5773f6e8e5766e5fcc7335b19dd068d1f20260085ecda8eba366ff1521997c5654630ef09ba421b871a3dc66aa0dd5eba8a3bc7052398a7ad779506d86cbf687e76cd9dc50969e222820d2f905c0550995a9c068725bb6c8b04358c965ab77221fdfd829e57ce54cac6e2fa62db15043d720b72fa8962dd718a0b42c34577af9cb4a5ed04c1ae17b7af470c0d8b77987dc9e2d2593a52458c4acb83b628b1488371de85f78a2e25aeaebc18d20a8c3007d08949e93b80087707afd1fe4e07a0afee4244e5270f768e234b86852aa1556c53ffc0d6f60661369a484d55d063119e71e70af1ec775908466cac7b12bc22e1a9525c2bfa9f83f7901c8e0a1d56387ef65040b750656b0b75791738b5b7e453f24167eae56c057c94e1e4cf1a0d08894225f11b45bc31827cad1dfe62e148549385953aa16a0410dba231aace3a7b9fd9b1c2b930f01193377b59736d8a8959ca5b449655f79a4dbec0da566083f90caa2490b01a10c0a86dd4aaa719bdc1e4233db17217f03509cc20dab7246730e3f964944990690b6dcc84936e1dd487bd154ceefe58a838a0488cc93b854a112ea67f6802d2f409915e648ee5cf5fdc3c12e41acbfab7caa9";
34
module_attack_exec(MAYBE_UNUSED const hashconfig_t * hashconfig,MAYBE_UNUSED const user_options_t * user_options,MAYBE_UNUSED const user_options_extra_t * user_options_extra)35 u32 module_attack_exec (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return ATTACK_EXEC; }
module_dgst_pos0(MAYBE_UNUSED const hashconfig_t * hashconfig,MAYBE_UNUSED const user_options_t * user_options,MAYBE_UNUSED const user_options_extra_t * user_options_extra)36 u32 module_dgst_pos0 (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return DGST_POS0; }
module_dgst_pos1(MAYBE_UNUSED const hashconfig_t * hashconfig,MAYBE_UNUSED const user_options_t * user_options,MAYBE_UNUSED const user_options_extra_t * user_options_extra)37 u32 module_dgst_pos1 (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return DGST_POS1; }
module_dgst_pos2(MAYBE_UNUSED const hashconfig_t * hashconfig,MAYBE_UNUSED const user_options_t * user_options,MAYBE_UNUSED const user_options_extra_t * user_options_extra)38 u32 module_dgst_pos2 (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return DGST_POS2; }
module_dgst_pos3(MAYBE_UNUSED const hashconfig_t * hashconfig,MAYBE_UNUSED const user_options_t * user_options,MAYBE_UNUSED const user_options_extra_t * user_options_extra)39 u32 module_dgst_pos3 (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return DGST_POS3; }
module_dgst_size(MAYBE_UNUSED const hashconfig_t * hashconfig,MAYBE_UNUSED const user_options_t * user_options,MAYBE_UNUSED const user_options_extra_t * user_options_extra)40 u32 module_dgst_size (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return DGST_SIZE; }
module_hash_category(MAYBE_UNUSED const hashconfig_t * hashconfig,MAYBE_UNUSED const user_options_t * user_options,MAYBE_UNUSED const user_options_extra_t * user_options_extra)41 u32 module_hash_category (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return HASH_CATEGORY; }
module_hash_name(MAYBE_UNUSED const hashconfig_t * hashconfig,MAYBE_UNUSED const user_options_t * user_options,MAYBE_UNUSED const user_options_extra_t * user_options_extra)42 const char *module_hash_name (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return HASH_NAME; }
module_kern_type(MAYBE_UNUSED const hashconfig_t * hashconfig,MAYBE_UNUSED const user_options_t * user_options,MAYBE_UNUSED const user_options_extra_t * user_options_extra)43 u64 module_kern_type (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return KERN_TYPE; }
module_opti_type(MAYBE_UNUSED const hashconfig_t * hashconfig,MAYBE_UNUSED const user_options_t * user_options,MAYBE_UNUSED const user_options_extra_t * user_options_extra)44 u32 module_opti_type (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return OPTI_TYPE; }
module_opts_type(MAYBE_UNUSED const hashconfig_t * hashconfig,MAYBE_UNUSED const user_options_t * user_options,MAYBE_UNUSED const user_options_extra_t * user_options_extra)45 u64 module_opts_type (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return OPTS_TYPE; }
module_salt_type(MAYBE_UNUSED const hashconfig_t * hashconfig,MAYBE_UNUSED const user_options_t * user_options,MAYBE_UNUSED const user_options_extra_t * user_options_extra)46 u32 module_salt_type (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return SALT_TYPE; }
module_st_hash(MAYBE_UNUSED const hashconfig_t * hashconfig,MAYBE_UNUSED const user_options_t * user_options,MAYBE_UNUSED const user_options_extra_t * user_options_extra)47 const char *module_st_hash (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return ST_HASH; }
module_st_pass(MAYBE_UNUSED const hashconfig_t * hashconfig,MAYBE_UNUSED const user_options_t * user_options,MAYBE_UNUSED const user_options_extra_t * user_options_extra)48 const char *module_st_pass (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return ST_PASS; }
49
50 typedef struct tc64_tmp
51 {
52 u64 ipad[8];
53 u64 opad[8];
54
55 u64 dgst[32];
56 u64 out[32];
57
58 } tc64_tmp_t;
59
60 typedef struct tc
61 {
62 u32 salt_buf[32];
63 u32 data_buf[112];
64 u32 keyfile_buf16[16];
65 u32 keyfile_buf32[32];
66 u32 keyfile_enabled;
67 u32 signature;
68
69 keyboard_layout_mapping_t keyboard_layout_mapping_buf[256];
70 int keyboard_layout_mapping_cnt;
71
72 } tc_t;
73
74 static const int ROUNDS_TRUECRYPT_1K = 1000;
75 static const float MIN_SUFFICIENT_ENTROPY_FILE = 7.0f;
76
module_unstable_warning(MAYBE_UNUSED const hashconfig_t * hashconfig,MAYBE_UNUSED const user_options_t * user_options,MAYBE_UNUSED const user_options_extra_t * user_options_extra,MAYBE_UNUSED const hc_device_param_t * device_param)77 bool module_unstable_warning (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra, MAYBE_UNUSED const hc_device_param_t *device_param)
78 {
79 if (device_param->opencl_platform_vendor_id == VENDOR_ID_APPLE)
80 {
81 // self-test failed
82 if ((device_param->opencl_device_vendor_id == VENDOR_ID_AMD) && (device_param->opencl_device_type & CL_DEVICE_TYPE_GPU))
83 {
84 return true;
85 }
86 }
87
88 return false;
89 }
90
module_potfile_disable(MAYBE_UNUSED const hashconfig_t * hashconfig,MAYBE_UNUSED const user_options_t * user_options,MAYBE_UNUSED const user_options_extra_t * user_options_extra)91 bool module_potfile_disable (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra)
92 {
93 const bool potfile_disable = true;
94
95 return potfile_disable;
96 }
97
module_outfile_check_disable(MAYBE_UNUSED const hashconfig_t * hashconfig,MAYBE_UNUSED const user_options_t * user_options,MAYBE_UNUSED const user_options_extra_t * user_options_extra)98 bool module_outfile_check_disable (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra)
99 {
100 const bool outfile_check_disable = true;
101
102 return outfile_check_disable;
103 }
104
module_esalt_size(MAYBE_UNUSED const hashconfig_t * hashconfig,MAYBE_UNUSED const user_options_t * user_options,MAYBE_UNUSED const user_options_extra_t * user_options_extra)105 u64 module_esalt_size (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra)
106 {
107 const u64 esalt_size = (const u64) sizeof (tc_t);
108
109 return esalt_size;
110 }
111
module_tmp_size(MAYBE_UNUSED const hashconfig_t * hashconfig,MAYBE_UNUSED const user_options_t * user_options,MAYBE_UNUSED const user_options_extra_t * user_options_extra)112 u64 module_tmp_size (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra)
113 {
114 const u64 tmp_size = (const u64) sizeof (tc64_tmp_t);
115
116 return tmp_size;
117 }
118
module_pw_max(MAYBE_UNUSED const hashconfig_t * hashconfig,MAYBE_UNUSED const user_options_t * user_options,MAYBE_UNUSED const user_options_extra_t * user_options_extra)119 u32 module_pw_max (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra)
120 {
121 // this overrides the reductions of PW_MAX in case optimized kernel is selected
122 // IOW, even in optimized kernel mode it support length 64
123
124 const u32 pw_max = 64;
125
126 return pw_max;
127 }
128
module_hash_init_selftest(MAYBE_UNUSED const hashconfig_t * hashconfig,hash_t * hash)129 int module_hash_init_selftest (MAYBE_UNUSED const hashconfig_t *hashconfig, hash_t *hash)
130 {
131 const size_t st_hash_len = strlen (hashconfig->st_hash);
132
133 char *tmpdata = (char *) hcmalloc (st_hash_len / 2);
134
135 for (size_t i = 0, j = 0; j < st_hash_len; i += 1, j += 2)
136 {
137 const u8 c = hex_to_u8 ((const u8 *) hashconfig->st_hash + j);
138
139 tmpdata[i] = c;
140 }
141
142 const int parser_status = module_hash_decode (hashconfig, hash->digest, hash->salt, hash->esalt, hash->hook_salt, hash->hash_info, tmpdata, st_hash_len / 2);
143
144 hcfree (tmpdata);
145
146 return parser_status;
147 }
148
module_hash_binary_parse(MAYBE_UNUSED const hashconfig_t * hashconfig,MAYBE_UNUSED const user_options_t * user_options,MAYBE_UNUSED const user_options_extra_t * user_options_extra,hashes_t * hashes)149 int module_hash_binary_parse (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra, hashes_t *hashes)
150 {
151 // note: if module_hash_binary_parse exists, then module_hash_decode is not called
152
153 HCFILE fp;
154
155 if (hc_fopen (&fp, hashes->hashfile, "rb") == false) return (PARSER_HAVE_ERRNO);
156
157 #define TC_HEADER_SIZE 512
158
159 char *in = (char *) hcmalloc (TC_HEADER_SIZE);
160
161 const size_t n = hc_fread (in, 1, TC_HEADER_SIZE, &fp);
162
163 hc_fclose (&fp);
164
165 if (n != TC_HEADER_SIZE) return (PARSER_TC_FILE_SIZE);
166
167 hash_t *hashes_buf = hashes->hashes_buf;
168
169 hash_t *hash = &hashes_buf[0];
170
171 const int parser_status = module_hash_decode (hashconfig, hash->digest, hash->salt, hash->esalt, hash->hook_salt, hash->hash_info, in, TC_HEADER_SIZE);
172
173 if (parser_status != PARSER_OK) return 0;
174
175 hcfree (in);
176
177 // keyfiles
178
179 tc_t *tc = (tc_t *) hash->esalt;
180
181 if (user_options->truecrypt_keyfiles)
182 {
183 char *keyfiles = hcstrdup (user_options->truecrypt_keyfiles);
184
185 char *saveptr = NULL;
186
187 char *keyfile = strtok_r (keyfiles, ",", &saveptr);
188
189 while (keyfile)
190 {
191 if (hc_path_read (keyfile))
192 {
193 cpu_crc32 (keyfile, (u8 *) tc->keyfile_buf16, 64);
194 cpu_crc32 (keyfile, (u8 *) tc->keyfile_buf32, 128);
195 }
196
197 keyfile = strtok_r ((char *) NULL, ",", &saveptr);
198 }
199
200 hcfree (keyfiles);
201
202 tc->keyfile_enabled = 1;
203 }
204
205 // keyboard layout mapping
206
207 if (user_options->keyboard_layout_mapping)
208 {
209 if (hc_path_read (user_options->keyboard_layout_mapping))
210 {
211 initialize_keyboard_layout_mapping (user_options->keyboard_layout_mapping, tc->keyboard_layout_mapping_buf, &tc->keyboard_layout_mapping_cnt);
212 }
213 }
214
215 return 1;
216 }
217
module_hash_decode(MAYBE_UNUSED const hashconfig_t * hashconfig,MAYBE_UNUSED void * digest_buf,MAYBE_UNUSED salt_t * salt,MAYBE_UNUSED void * esalt_buf,MAYBE_UNUSED void * hook_salt_buf,MAYBE_UNUSED hashinfo_t * hash_info,const char * line_buf,MAYBE_UNUSED const int line_len)218 int module_hash_decode (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED void *digest_buf, MAYBE_UNUSED salt_t *salt, MAYBE_UNUSED void *esalt_buf, MAYBE_UNUSED void *hook_salt_buf, MAYBE_UNUSED hashinfo_t *hash_info, const char *line_buf, MAYBE_UNUSED const int line_len)
219 {
220 u32 *digest = (u32 *) digest_buf;
221
222 tc_t *tc = (tc_t *) esalt_buf;
223
224 const float entropy = get_entropy ((const u8 *) line_buf, line_len);
225
226 if (entropy < MIN_SUFFICIENT_ENTROPY_FILE) return (PARSER_INSUFFICIENT_ENTROPY);
227
228 memcpy (tc->salt_buf, line_buf, 64);
229
230 memcpy (tc->data_buf, line_buf + 64, 512 - 64);
231
232 salt->salt_buf[0] = tc->salt_buf[0];
233
234 salt->salt_len = 4;
235
236 salt->salt_iter = ROUNDS_TRUECRYPT_1K - 1;
237
238 tc->signature = 0x45555254; // "TRUE"
239
240 digest[0] = tc->data_buf[0];
241
242 return (PARSER_OK);
243 }
244
module_init(module_ctx_t * module_ctx)245 void module_init (module_ctx_t *module_ctx)
246 {
247 module_ctx->module_context_size = MODULE_CONTEXT_SIZE_CURRENT;
248 module_ctx->module_interface_version = MODULE_INTERFACE_VERSION_CURRENT;
249
250 module_ctx->module_attack_exec = module_attack_exec;
251 module_ctx->module_benchmark_esalt = MODULE_DEFAULT;
252 module_ctx->module_benchmark_hook_salt = MODULE_DEFAULT;
253 module_ctx->module_benchmark_mask = MODULE_DEFAULT;
254 module_ctx->module_benchmark_salt = MODULE_DEFAULT;
255 module_ctx->module_build_plain_postprocess = MODULE_DEFAULT;
256 module_ctx->module_deep_comp_kernel = MODULE_DEFAULT;
257 module_ctx->module_deprecated_notice = MODULE_DEFAULT;
258 module_ctx->module_dgst_pos0 = module_dgst_pos0;
259 module_ctx->module_dgst_pos1 = module_dgst_pos1;
260 module_ctx->module_dgst_pos2 = module_dgst_pos2;
261 module_ctx->module_dgst_pos3 = module_dgst_pos3;
262 module_ctx->module_dgst_size = module_dgst_size;
263 module_ctx->module_dictstat_disable = MODULE_DEFAULT;
264 module_ctx->module_esalt_size = module_esalt_size;
265 module_ctx->module_extra_buffer_size = MODULE_DEFAULT;
266 module_ctx->module_extra_tmp_size = MODULE_DEFAULT;
267 module_ctx->module_extra_tuningdb_block = MODULE_DEFAULT;
268 module_ctx->module_forced_outfile_format = MODULE_DEFAULT;
269 module_ctx->module_hash_binary_count = MODULE_DEFAULT;
270 module_ctx->module_hash_binary_parse = module_hash_binary_parse;
271 module_ctx->module_hash_binary_save = MODULE_DEFAULT;
272 module_ctx->module_hash_decode_potfile = MODULE_DEFAULT;
273 module_ctx->module_hash_decode_zero_hash = MODULE_DEFAULT;
274 module_ctx->module_hash_decode = module_hash_decode;
275 module_ctx->module_hash_encode_status = MODULE_DEFAULT;
276 module_ctx->module_hash_encode_potfile = MODULE_DEFAULT;
277 module_ctx->module_hash_encode = MODULE_DEFAULT;
278 module_ctx->module_hash_init_selftest = module_hash_init_selftest;
279 module_ctx->module_hash_mode = MODULE_DEFAULT;
280 module_ctx->module_hash_category = module_hash_category;
281 module_ctx->module_hash_name = module_hash_name;
282 module_ctx->module_hashes_count_min = MODULE_DEFAULT;
283 module_ctx->module_hashes_count_max = MODULE_DEFAULT;
284 module_ctx->module_hlfmt_disable = MODULE_DEFAULT;
285 module_ctx->module_hook_extra_param_size = MODULE_DEFAULT;
286 module_ctx->module_hook_extra_param_init = MODULE_DEFAULT;
287 module_ctx->module_hook_extra_param_term = MODULE_DEFAULT;
288 module_ctx->module_hook12 = MODULE_DEFAULT;
289 module_ctx->module_hook23 = MODULE_DEFAULT;
290 module_ctx->module_hook_salt_size = MODULE_DEFAULT;
291 module_ctx->module_hook_size = MODULE_DEFAULT;
292 module_ctx->module_jit_build_options = MODULE_DEFAULT;
293 module_ctx->module_jit_cache_disable = MODULE_DEFAULT;
294 module_ctx->module_kernel_accel_max = MODULE_DEFAULT;
295 module_ctx->module_kernel_accel_min = MODULE_DEFAULT;
296 module_ctx->module_kernel_loops_max = MODULE_DEFAULT;
297 module_ctx->module_kernel_loops_min = MODULE_DEFAULT;
298 module_ctx->module_kernel_threads_max = MODULE_DEFAULT;
299 module_ctx->module_kernel_threads_min = MODULE_DEFAULT;
300 module_ctx->module_kern_type = module_kern_type;
301 module_ctx->module_kern_type_dynamic = MODULE_DEFAULT;
302 module_ctx->module_opti_type = module_opti_type;
303 module_ctx->module_opts_type = module_opts_type;
304 module_ctx->module_outfile_check_disable = module_outfile_check_disable;
305 module_ctx->module_outfile_check_nocomp = MODULE_DEFAULT;
306 module_ctx->module_potfile_custom_check = MODULE_DEFAULT;
307 module_ctx->module_potfile_disable = module_potfile_disable;
308 module_ctx->module_potfile_keep_all_hashes = MODULE_DEFAULT;
309 module_ctx->module_pwdump_column = MODULE_DEFAULT;
310 module_ctx->module_pw_max = module_pw_max;
311 module_ctx->module_pw_min = MODULE_DEFAULT;
312 module_ctx->module_salt_max = MODULE_DEFAULT;
313 module_ctx->module_salt_min = MODULE_DEFAULT;
314 module_ctx->module_salt_type = module_salt_type;
315 module_ctx->module_separator = MODULE_DEFAULT;
316 module_ctx->module_st_hash = module_st_hash;
317 module_ctx->module_st_pass = module_st_pass;
318 module_ctx->module_tmp_size = module_tmp_size;
319 module_ctx->module_unstable_warning = module_unstable_warning;
320 module_ctx->module_warmup_disable = MODULE_DEFAULT;
321 }
322