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 "emu_inc_cipher_des.h"
13
14 static const u32 ATTACK_EXEC = ATTACK_EXEC_OUTSIDE_KERNEL;
15 static const u32 DGST_POS0 = 0;
16 static const u32 DGST_POS1 = 1;
17 static const u32 DGST_POS2 = 2;
18 static const u32 DGST_POS3 = 3;
19 static const u32 DGST_SIZE = DGST_SIZE_4_4;
20 static const u32 HASH_CATEGORY = HASH_CATEGORY_OS;
21 static const char *HASH_NAME = "BSDi Crypt, Extended DES";
22 static const u64 KERN_TYPE = 12400;
23 static const u32 OPTI_TYPE = OPTI_TYPE_ZERO_BYTE
24 | OPTI_TYPE_REGISTER_LIMIT;
25 static const u64 OPTS_TYPE = OPTS_TYPE_PT_GENERATE_LE
26 | OPTS_TYPE_MAXIMUM_THREADS;
27 static const u32 SALT_TYPE = SALT_TYPE_EMBEDDED;
28 static const char *ST_PASS = "hashcat";
29 static const char *ST_HASH = "_GW..8841inaTltazRsQ";
30
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)31 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)32 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)33 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)34 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)35 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)36 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)37 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)38 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)39 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)40 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)41 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)42 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)43 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)44 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; }
45
46 typedef struct bsdicrypt_tmp
47 {
48 u32 Kc[16];
49 u32 Kd[16];
50
51 u32 iv[2];
52
53 } bsdicrypt_tmp_t;
54
55 static const char *SIGNATURE_BSDICRYPT = "_";
56
module_jit_build_options(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 hashes_t * hashes,MAYBE_UNUSED const hc_device_param_t * device_param)57 char *module_jit_build_options (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 hashes_t *hashes, MAYBE_UNUSED const hc_device_param_t *device_param)
58 {
59 char *jit_build_options = NULL;
60
61 // Extra treatment for Apple systems
62 if (device_param->opencl_platform_vendor_id == VENDOR_ID_APPLE)
63 {
64 return jit_build_options;
65 }
66
67 // NVIDIA GPU
68 if (device_param->opencl_device_vendor_id == VENDOR_ID_NV)
69 {
70 hc_asprintf (&jit_build_options, "-D _unroll");
71 }
72
73 return jit_build_options;
74 }
75
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)76 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)
77 {
78 const u64 tmp_size = (const u64) sizeof (bsdicrypt_tmp_t);
79
80 return tmp_size;
81 }
82
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)83 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)
84 {
85 const u32 pw_max = PW_MAX;
86
87 return pw_max;
88 }
89
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)90 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)
91 {
92 u32 *digest = (u32 *) digest_buf;
93
94 token_t token;
95
96 token.token_cnt = 4;
97
98 token.signatures_cnt = 1;
99 token.signatures_buf[0] = SIGNATURE_BSDICRYPT;
100
101 token.len[0] = 1;
102 token.attr[0] = TOKEN_ATTR_FIXED_LENGTH
103 | TOKEN_ATTR_VERIFY_SIGNATURE;
104
105 token.len[1] = 4;
106 token.attr[1] = TOKEN_ATTR_FIXED_LENGTH
107 | TOKEN_ATTR_VERIFY_BASE64B;
108
109 token.len[2] = 4;
110 token.attr[2] = TOKEN_ATTR_FIXED_LENGTH
111 | TOKEN_ATTR_VERIFY_BASE64B;
112
113 token.len[3] = 11;
114 token.attr[3] = TOKEN_ATTR_FIXED_LENGTH
115 | TOKEN_ATTR_VERIFY_BASE64B;
116
117 const int rc_tokenizer = input_tokenizer ((const u8 *) line_buf, line_len, &token);
118
119 if (rc_tokenizer != PARSER_OK) return (rc_tokenizer);
120
121 // iteration count
122
123 const u8 *iter_pos = token.buf[1];
124
125 salt->salt_iter = itoa64_to_int (iter_pos[0])
126 | itoa64_to_int (iter_pos[1]) << 6
127 | itoa64_to_int (iter_pos[2]) << 12
128 | itoa64_to_int (iter_pos[3]) << 18;
129
130 // set salt
131
132 const u8 *salt_pos = token.buf[2];
133
134 salt->salt_buf[0] = itoa64_to_int (salt_pos[0])
135 | itoa64_to_int (salt_pos[1]) << 6
136 | itoa64_to_int (salt_pos[2]) << 12
137 | itoa64_to_int (salt_pos[3]) << 18;
138
139 salt->salt_len = 4;
140
141 // hash
142
143 const u8 *hash_pos = token.buf[3];
144 const int hash_len = token.len[3];
145
146 unsigned char c19 = itoa64_to_int (hash_pos[10]);
147
148 if (c19 & 3) return (PARSER_HASH_VALUE);
149
150 u8 tmp_buf[100] = { 0 };
151
152 base64_decode (itoa64_to_int, hash_pos, hash_len, tmp_buf);
153
154 memcpy (digest, tmp_buf, 8);
155
156 DES_IP (digest[0], digest[1]);
157
158 digest[0] = rotr32 (digest[0], 31);
159 digest[1] = rotr32 (digest[1], 31);
160 digest[2] = 0;
161 digest[3] = 0;
162
163 return (PARSER_OK);
164 }
165
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)166 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)
167 {
168 const u32 *digest = (const u32 *) digest_buf;
169
170 // encode iteration count
171
172 char salt_iter[5];
173
174 salt_iter[0] = int_to_itoa64 ((salt->salt_iter ) & 0x3f);
175 salt_iter[1] = int_to_itoa64 ((salt->salt_iter >> 6) & 0x3f);
176 salt_iter[2] = int_to_itoa64 ((salt->salt_iter >> 12) & 0x3f);
177 salt_iter[3] = int_to_itoa64 ((salt->salt_iter >> 18) & 0x3f);
178 salt_iter[4] = 0;
179
180 // encode salt
181
182 char ptr_salt[5];
183
184 ptr_salt[0] = int_to_itoa64 ((salt->salt_buf[0] ) & 0x3f);
185 ptr_salt[1] = int_to_itoa64 ((salt->salt_buf[0] >> 6) & 0x3f);
186 ptr_salt[2] = int_to_itoa64 ((salt->salt_buf[0] >> 12) & 0x3f);
187 ptr_salt[3] = int_to_itoa64 ((salt->salt_buf[0] >> 18) & 0x3f);
188 ptr_salt[4] = 0;
189
190 // encode digest
191
192 u32 tmp[2];
193
194 tmp[0] = rotl32 (digest[0], 31);
195 tmp[1] = rotl32 (digest[1], 31);
196
197 DES_FP (tmp[1], tmp[0]);
198
199 char ptr_plain[12];
200
201 base64_encode (int_to_itoa64, (const u8 *) tmp, 8, (u8 *) ptr_plain);
202
203 ptr_plain[11] = 0;
204
205 // fill the resulting buffer
206
207 const int line_len = snprintf (line_buf, line_size, "_%s%s%s", salt_iter, ptr_salt, ptr_plain);
208
209 return line_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_DEFAULT;
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_jit_build_options;
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_DEFAULT;
287 module_ctx->module_warmup_disable = MODULE_DEFAULT;
288 }
289