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_INSIDE_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; // originally DGST_SIZE_4_2
20 static const u32 HASH_CATEGORY = HASH_CATEGORY_RAW_CIPHER_KPA;
21 static const char *HASH_NAME = "DES (PT = $salt, key = $pass)";
22 static const u64 KERN_TYPE = 14000;
23 static const u32 OPTI_TYPE = OPTI_TYPE_ZERO_BYTE;
24 static const u64 OPTS_TYPE = OPTS_TYPE_PT_GENERATE_LE
25 | OPTS_TYPE_TM_KERNEL
26 | OPTS_TYPE_ST_HEX;
27 static const u32 SALT_TYPE = SALT_TYPE_EMBEDDED;
28 static const char *ST_PASS = "hashcat1";
29 static const char *ST_HASH = "53b325182924b356:1412781058343178";
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
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)46 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)
47 {
48 // Intel(R) Xeon(R) W-3223 CPU @ 3.50GHz; OpenCL C 1.2; 11.3.1; 20E241
49 if ((device_param->opencl_platform_vendor_id == VENDOR_ID_APPLE) && (device_param->opencl_device_type & CL_DEVICE_TYPE_CPU))
50 {
51 return true;
52 }
53
54 return false;
55 }
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 // Intel CPU
68 if ((device_param->opencl_device_vendor_id == VENDOR_ID_INTEL_SDK) && (device_param->opencl_device_type & CL_DEVICE_TYPE_CPU))
69 {
70 hc_asprintf (&jit_build_options, "-D _unroll");
71 }
72
73 // AMD-GPU-PRO
74 if ((device_param->opencl_device_vendor_id == VENDOR_ID_AMD) && (device_param->has_vperm == false))
75 {
76 hc_asprintf (&jit_build_options, "-D _unroll");
77 }
78
79 // HIP
80 if (device_param->opencl_device_vendor_id == VENDOR_ID_AMD_USE_HIP)
81 {
82 hc_asprintf (&jit_build_options, "-D _unroll");
83 }
84
85 // ROCM
86 if ((device_param->opencl_device_vendor_id == VENDOR_ID_AMD) && (device_param->has_vperm == true))
87 {
88 hc_asprintf (&jit_build_options, "-D _unroll");
89 }
90
91 return jit_build_options;
92 }
93
module_kernel_loops_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)94 u32 module_kernel_loops_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)
95 {
96 u32 kernel_loops_max = KERNEL_LOOPS_MAX;
97
98 if (user_options->slow_candidates == false)
99 {
100 if (user_options->attack_mode == ATTACK_MODE_BF)
101 {
102 kernel_loops_max = 1024;
103 }
104 }
105
106 return kernel_loops_max;
107 }
108
module_kernel_loops_min(MAYBE_UNUSED const hashconfig_t * hashconfig,MAYBE_UNUSED const user_options_t * user_options,MAYBE_UNUSED const user_options_extra_t * user_options_extra)109 u32 module_kernel_loops_min (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra)
110 {
111 u32 kernel_loops_min = KERNEL_LOOPS_MIN;
112
113 if (user_options->slow_candidates == false)
114 {
115 if (user_options->attack_mode == ATTACK_MODE_BF)
116 {
117 kernel_loops_min = 1024;
118 }
119 }
120
121 return kernel_loops_min;
122 }
123
module_salt_min(MAYBE_UNUSED const hashconfig_t * hashconfig,MAYBE_UNUSED const user_options_t * user_options,MAYBE_UNUSED const user_options_extra_t * user_options_extra)124 u32 module_salt_min (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra)
125 {
126 const u32 salt_min = 8; // Underlaying DES min
127
128 return salt_min;
129 }
130
module_salt_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)131 u32 module_salt_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)
132 {
133 const u32 salt_max = 8; // Underlaying DES max
134
135 return salt_max;
136 }
137
module_pw_min(MAYBE_UNUSED const hashconfig_t * hashconfig,MAYBE_UNUSED const user_options_t * user_options,MAYBE_UNUSED const user_options_extra_t * user_options_extra)138 u32 module_pw_min (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra)
139 {
140 const u32 pw_min = 8; // Underlaying DES min
141
142 return pw_min;
143 }
144
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)145 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)
146 {
147 const u32 pw_max = 8; // Underlaying DES max
148
149 return pw_max;
150 }
151
module_benchmark_mask(MAYBE_UNUSED const hashconfig_t * hashconfig,MAYBE_UNUSED const user_options_t * user_options,MAYBE_UNUSED const user_options_extra_t * user_options_extra)152 const char *module_benchmark_mask (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra)
153 {
154 const char *mask = "?b?b?b?b?b?b?bx";
155
156 return mask;
157 }
158
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)159 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)
160 {
161 u32 *digest = (u32 *) digest_buf;
162
163 token_t token;
164
165 token.token_cnt = 2;
166
167 token.sep[0] = hashconfig->separator;
168 token.len_min[0] = 16;
169 token.len_max[0] = 16;
170 token.attr[0] = TOKEN_ATTR_VERIFY_LENGTH
171 | TOKEN_ATTR_VERIFY_HEX;
172
173 token.len_min[1] = 16;
174 token.len_max[1] = 16;
175 token.attr[1] = TOKEN_ATTR_VERIFY_LENGTH
176 | TOKEN_ATTR_VERIFY_HEX;
177
178 const int rc_tokenizer = input_tokenizer ((const u8 *) line_buf, line_len, &token);
179
180 if (rc_tokenizer != PARSER_OK) return (rc_tokenizer);
181
182 // salt
183
184 const u8 *salt_pos = token.buf[1];
185
186 salt->salt_buf[0] = hex_to_u32 (salt_pos + 0);
187 salt->salt_buf[1] = hex_to_u32 (salt_pos + 8);
188 salt->salt_buf[2] = 0;
189 salt->salt_buf[3] = 0;
190
191 salt->salt_len = 8;
192
193 salt->salt_buf_pc[0] = salt->salt_buf[0];
194 salt->salt_buf_pc[1] = salt->salt_buf[1];
195
196 DES_IP (salt->salt_buf_pc[0], salt->salt_buf_pc[1]);
197
198 // hash
199
200 const u8 *hash_pos = token.buf[0];
201
202 digest[0] = hex_to_u32 (hash_pos + 0);
203 digest[1] = hex_to_u32 (hash_pos + 8);
204 digest[2] = 0;
205 digest[3] = 0;
206
207 DES_IP (digest[0], digest[1]);
208
209 return (PARSER_OK);
210 }
211
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)212 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)
213 {
214 const u32 *digest = (const u32 *) digest_buf;
215
216 // we can not change anything in the original buffer, otherwise destroying sorting
217 // therefore create some local buffer
218
219 u32 tmp[4];
220
221 tmp[0] = digest[0];
222 tmp[1] = digest[1];
223 tmp[2] = 0;
224 tmp[3] = 0;
225
226 DES_FP (tmp[1], tmp[0]);
227
228 u8 *out_buf = (u8 *) line_buf;
229
230 int out_len = 0;
231
232 u32_to_hex (tmp[0], out_buf + out_len); out_len += 8;
233 u32_to_hex (tmp[1], out_buf + out_len); out_len += 8;
234
235 out_buf[out_len] = hashconfig->separator;
236
237 out_len++;
238
239 u32_to_hex (salt->salt_buf[0], out_buf + out_len); out_len += 8;
240 u32_to_hex (salt->salt_buf[1], out_buf + out_len); out_len += 8;
241
242 return out_len;
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_benchmark_mask;
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_DEFAULT;
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_DEFAULT;
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_hash_encode;
278 module_ctx->module_hash_init_selftest = MODULE_DEFAULT;
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_jit_build_options;
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_kernel_loops_max;
297 module_ctx->module_kernel_loops_min = module_kernel_loops_min;
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_DEFAULT;
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_DEFAULT;
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_pw_min;
312 module_ctx->module_salt_max = module_salt_max;
313 module_ctx->module_salt_min = module_salt_min;
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_DEFAULT;
319 module_ctx->module_unstable_warning = module_unstable_warning;
320 module_ctx->module_warmup_disable = MODULE_DEFAULT;
321 }
322