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 
13 static const u32   ATTACK_EXEC    = ATTACK_EXEC_OUTSIDE_KERNEL;
14 static const u32   DGST_POS0      = 0;
15 static const u32   DGST_POS1      = 1;
16 static const u32   DGST_POS2      = 2;
17 static const u32   DGST_POS3      = 3;
18 static const u32   DGST_SIZE      = DGST_SIZE_4_4;
19 static const u32   HASH_CATEGORY  = HASH_CATEGORY_FDE;
20 static const char *HASH_NAME      = "BestCrypt v3 Volume Encryption";
21 static const u64   KERN_TYPE      = 23900;
22 static const u32   OPTI_TYPE      = OPTI_TYPE_ZERO_BYTE;
23 static const u64   OPTS_TYPE      = OPTS_TYPE_PT_GENERATE_LE
24                                   | OPTS_TYPE_ST_HEX;
25 static const u32   SALT_TYPE      = SALT_TYPE_EMBEDDED;
26 static const char *ST_PASS        = "hashcat";
27 static const char *ST_HASH        = "$bcve$3$08$234b8182cee7098b$35c12ef76a1e88175c4c222da3558310a0075bc7a06ecf46746d149c02a81fb8a97637d1103d2e13ddd5deaf982889594b18c12d7ca18a54875c5da4a47f90ae615ab94b8e3ed9e3c793d872a1b5ac35cfdb66c221d6d0853e9ff2e0f4435b43";
28 
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)29 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)30 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)31 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)32 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)33 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)34 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)35 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)36 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)37 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)38 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)39 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)40 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)41 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)42 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;         }
43 
44 typedef struct bestcrypt_tmp
45 {
46   u32 salt_pw_buf[33];
47   u32 out[8];
48 
49 } bestcrypt_tmp_t;
50 
51 typedef struct bestcrypt
52 {
53   u32 data[24];
54 
55 } bestcrypt_t;
56 
57 static const char *SIGNATURE_BESTCRYPT  = "$bcve$";
58 
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)59 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)
60 {
61   // amdgpu-pro-20.50-1234664-ubuntu-20.04 (legacy)
62   // test_1619943729/test_report.log:! unhandled return code 255, cmdline : cat test_1619943729/23900_passwords.txt | ./hashcat --quiet --potfile-disable --runtime 400 --hwmon-disable -O -D 2 --backend-vector-width 1 -a 0 -m 23900 test_1619943729/23900_hashes.txt
63   // test_1619955152/test_report.log:! unhandled return code 255, cmdline : cat test_1619955152/23900_passwords.txt | ./hashcat --quiet --potfile-disable --runtime 400 --hwmon-disable -D 2 --backend-vector-width 4 -a 0 -m 23900 test_1619955152/23900_hashes.txt
64   if ((device_param->opencl_device_vendor_id == VENDOR_ID_AMD) && (device_param->has_vperm == false))
65   {
66     return true;
67   }
68 
69   return false;
70 }
71 
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)72 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)
73 {
74   const u64 tmp_size = (const u64) sizeof (bestcrypt_tmp_t);
75 
76   return tmp_size;
77 }
78 
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)79 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)
80 {
81   const u64 esalt_size = (const u64) sizeof (bestcrypt_t);
82 
83   return esalt_size;
84 }
85 
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)86 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)
87 {
88   // this overrides the reductions of PW_MAX in case optimized kernel is selected
89   // IOW, even in optimized kernel mode it support length 56
90 
91   const u32 pw_max = 56;
92 
93   return pw_max;
94 }
95 
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)96 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)
97 {
98   u32 *digest = (u32 *) digest_buf;
99 
100   bestcrypt_t *bestcrypt = (bestcrypt_t *) esalt_buf;
101 
102   token_t token;
103 
104   token.token_cnt  = 5;
105 
106   token.signatures_cnt    = 1;
107   token.signatures_buf[0] = SIGNATURE_BESTCRYPT;
108 
109   token.len[0]     = 6;
110   token.attr[0]    = TOKEN_ATTR_FIXED_LENGTH
111                    | TOKEN_ATTR_VERIFY_SIGNATURE;
112 
113   token.len_min[1] = 1;
114   token.len_max[1] = 1;
115   token.sep[1]     = '$';
116   token.attr[1]    = TOKEN_ATTR_VERIFY_LENGTH
117                    | TOKEN_ATTR_VERIFY_DIGIT;
118 
119   token.len_min[2] = 2;
120   token.len_max[2] = 2;
121   token.sep[2]     = '$';
122   token.attr[2]    = TOKEN_ATTR_VERIFY_LENGTH
123                    | TOKEN_ATTR_VERIFY_HEX;
124 
125   token.len_min[3] = 16;
126   token.len_max[3] = 16;
127   token.sep[3]     = '$';
128   token.attr[3]    = TOKEN_ATTR_VERIFY_LENGTH
129                    | TOKEN_ATTR_VERIFY_HEX;
130 
131   token.len[4]     = 192;
132   token.attr[4]    = TOKEN_ATTR_FIXED_LENGTH
133                    | TOKEN_ATTR_VERIFY_HEX;
134 
135   const int rc_tokenizer = input_tokenizer ((const u8 *) line_buf, line_len, &token);
136 
137   if (rc_tokenizer != PARSER_OK) return (rc_tokenizer);
138 
139   const u8 *format_type_pos = token.buf[1];
140 
141   if (format_type_pos[0] != '3') return (PARSER_SALT_VALUE);
142 
143   const u8 *crypto_type_pos = token.buf[2];
144 
145   if (crypto_type_pos[0] != '0') return (PARSER_SALT_VALUE);
146   if (crypto_type_pos[1] != '8') return (PARSER_SALT_VALUE);
147 
148   salt->salt_iter = 1;
149 
150   // salt
151 
152   const u8 *salt_pos = token.buf[3];
153   const int salt_len = token.len[3];
154 
155   const bool parse_rc = generic_salt_decode (hashconfig, salt_pos, salt_len, (u8 *) salt->salt_buf, (int *) &salt->salt_len);
156 
157   if (parse_rc == false) return (PARSER_SALT_LENGTH);
158 
159   salt->salt_buf[0] = salt->salt_buf[0];
160   salt->salt_buf[1] = salt->salt_buf[1];
161 
162   salt->salt_buf[0] = byte_swap_32 (salt->salt_buf[0]);
163   salt->salt_buf[1] = byte_swap_32 (salt->salt_buf[1]);
164 
165   // data
166 
167   const u8 *data_pos = token.buf[4];
168   const int data_len = token.len[4];
169 
170   hex_decode (data_pos, data_len, (u8 *) bestcrypt->data);
171 
172   // fake digest
173 
174   digest[0] = bestcrypt->data[16]; // the encrypted checksum
175   digest[1] = bestcrypt->data[17];
176   digest[2] = bestcrypt->data[18];
177   digest[3] = bestcrypt->data[19];
178 
179   return (PARSER_OK);
180 }
181 
module_hash_encode(MAYBE_UNUSED const hashconfig_t * hashconfig,MAYBE_UNUSED const void * digest_buf,MAYBE_UNUSED const salt_t * salt,MAYBE_UNUSED const void * esalt_buf,MAYBE_UNUSED const void * hook_salt_buf,MAYBE_UNUSED const hashinfo_t * hash_info,char * line_buf,MAYBE_UNUSED const int line_size)182 int module_hash_encode (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const void *digest_buf, MAYBE_UNUSED const salt_t *salt, MAYBE_UNUSED const void *esalt_buf, MAYBE_UNUSED const void *hook_salt_buf, MAYBE_UNUSED const hashinfo_t *hash_info, char *line_buf, MAYBE_UNUSED const int line_size)
183 {
184   const bestcrypt_t *bestcrypt = (const bestcrypt_t *) esalt_buf;
185 
186   // salt
187 
188   u32 tmp_salt[4] = { 0 };
189 
190   tmp_salt[0] = byte_swap_32 (salt->salt_buf[0]);
191   tmp_salt[1] = byte_swap_32 (salt->salt_buf[1]);
192 
193   char salt_hex[17] = { 0 };
194 
195   generic_salt_encode (hashconfig, (const u8 *) tmp_salt, (const int) salt->salt_len, (u8 *) salt_hex);
196 
197   // data
198 
199   u8 data_hex[193] = { 0 };
200 
201   hex_encode ((u8 *) bestcrypt->data, 96, data_hex);
202 
203   int out_len = snprintf (line_buf, line_size, "%s3$08$%s$%s",
204     SIGNATURE_BESTCRYPT,
205     salt_hex,
206     data_hex
207   );
208 
209   return out_len;
210 }
211 
module_init(module_ctx_t * module_ctx)212 void module_init (module_ctx_t *module_ctx)
213 {
214   module_ctx->module_context_size             = MODULE_CONTEXT_SIZE_CURRENT;
215   module_ctx->module_interface_version        = MODULE_INTERFACE_VERSION_CURRENT;
216 
217   module_ctx->module_attack_exec              = module_attack_exec;
218   module_ctx->module_benchmark_esalt          = MODULE_DEFAULT;
219   module_ctx->module_benchmark_hook_salt      = MODULE_DEFAULT;
220   module_ctx->module_benchmark_mask           = MODULE_DEFAULT;
221   module_ctx->module_benchmark_salt           = MODULE_DEFAULT;
222   module_ctx->module_build_plain_postprocess  = MODULE_DEFAULT;
223   module_ctx->module_deep_comp_kernel         = MODULE_DEFAULT;
224   module_ctx->module_deprecated_notice        = MODULE_DEFAULT;
225   module_ctx->module_dgst_pos0                = module_dgst_pos0;
226   module_ctx->module_dgst_pos1                = module_dgst_pos1;
227   module_ctx->module_dgst_pos2                = module_dgst_pos2;
228   module_ctx->module_dgst_pos3                = module_dgst_pos3;
229   module_ctx->module_dgst_size                = module_dgst_size;
230   module_ctx->module_dictstat_disable         = MODULE_DEFAULT;
231   module_ctx->module_esalt_size               = module_esalt_size;
232   module_ctx->module_extra_buffer_size        = MODULE_DEFAULT;
233   module_ctx->module_extra_tmp_size           = MODULE_DEFAULT;
234   module_ctx->module_extra_tuningdb_block     = MODULE_DEFAULT;
235   module_ctx->module_forced_outfile_format    = MODULE_DEFAULT;
236   module_ctx->module_hash_binary_count        = MODULE_DEFAULT;
237   module_ctx->module_hash_binary_parse        = MODULE_DEFAULT;
238   module_ctx->module_hash_binary_save         = MODULE_DEFAULT;
239   module_ctx->module_hash_decode_potfile      = MODULE_DEFAULT;
240   module_ctx->module_hash_decode_zero_hash    = MODULE_DEFAULT;
241   module_ctx->module_hash_decode              = module_hash_decode;
242   module_ctx->module_hash_encode_status       = MODULE_DEFAULT;
243   module_ctx->module_hash_encode_potfile      = MODULE_DEFAULT;
244   module_ctx->module_hash_encode              = module_hash_encode;
245   module_ctx->module_hash_init_selftest       = MODULE_DEFAULT;
246   module_ctx->module_hash_mode                = MODULE_DEFAULT;
247   module_ctx->module_hash_category            = module_hash_category;
248   module_ctx->module_hash_name                = module_hash_name;
249   module_ctx->module_hashes_count_min         = MODULE_DEFAULT;
250   module_ctx->module_hashes_count_max         = MODULE_DEFAULT;
251   module_ctx->module_hlfmt_disable            = MODULE_DEFAULT;
252   module_ctx->module_hook_extra_param_size    = MODULE_DEFAULT;
253   module_ctx->module_hook_extra_param_init    = MODULE_DEFAULT;
254   module_ctx->module_hook_extra_param_term    = MODULE_DEFAULT;
255   module_ctx->module_hook12                   = MODULE_DEFAULT;
256   module_ctx->module_hook23                   = MODULE_DEFAULT;
257   module_ctx->module_hook_salt_size           = MODULE_DEFAULT;
258   module_ctx->module_hook_size                = MODULE_DEFAULT;
259   module_ctx->module_jit_build_options        = MODULE_DEFAULT;
260   module_ctx->module_jit_cache_disable        = MODULE_DEFAULT;
261   module_ctx->module_kernel_accel_max         = MODULE_DEFAULT;
262   module_ctx->module_kernel_accel_min         = MODULE_DEFAULT;
263   module_ctx->module_kernel_loops_max         = MODULE_DEFAULT;
264   module_ctx->module_kernel_loops_min         = MODULE_DEFAULT;
265   module_ctx->module_kernel_threads_max       = MODULE_DEFAULT;
266   module_ctx->module_kernel_threads_min       = MODULE_DEFAULT;
267   module_ctx->module_kern_type                = module_kern_type;
268   module_ctx->module_kern_type_dynamic        = MODULE_DEFAULT;
269   module_ctx->module_opti_type                = module_opti_type;
270   module_ctx->module_opts_type                = module_opts_type;
271   module_ctx->module_outfile_check_disable    = MODULE_DEFAULT;
272   module_ctx->module_outfile_check_nocomp     = MODULE_DEFAULT;
273   module_ctx->module_potfile_custom_check     = MODULE_DEFAULT;
274   module_ctx->module_potfile_disable          = MODULE_DEFAULT;
275   module_ctx->module_potfile_keep_all_hashes  = MODULE_DEFAULT;
276   module_ctx->module_pwdump_column            = MODULE_DEFAULT;
277   module_ctx->module_pw_max                   = module_pw_max;
278   module_ctx->module_pw_min                   = MODULE_DEFAULT;
279   module_ctx->module_salt_max                 = MODULE_DEFAULT;
280   module_ctx->module_salt_min                 = MODULE_DEFAULT;
281   module_ctx->module_salt_type                = module_salt_type;
282   module_ctx->module_separator                = MODULE_DEFAULT;
283   module_ctx->module_st_hash                  = module_st_hash;
284   module_ctx->module_st_pass                  = module_st_pass;
285   module_ctx->module_tmp_size                 = module_tmp_size;
286   module_ctx->module_unstable_warning         = module_unstable_warning;
287   module_ctx->module_warmup_disable           = MODULE_DEFAULT;
288 }
289