1 /**
2 * Author......: See docs/credits.txt
3 * License.....: MIT
4 */
5
6 #include "common.h"
7 #include "types.h"
8 #include "memory.h"
9 #include "event.h"
10 #include "logfile.h"
11 #include "interface.h"
12 #include "shared.h"
13 #include "usage.h"
14 #include "backend.h"
15 #include "user_options.h"
16 #include "outfile.h"
17
18 #ifdef WITH_BRAIN
19 #include "brain.h"
20 #endif
21
22 #ifdef WITH_BRAIN
23 static const char *const short_options = "hVvm:a:r:j:k:g:o:t:d:D:n:u:T:c:p:s:l:1:2:3:4:iIbw:OMSz";
24 #else
25 static const char *const short_options = "hVvm:a:r:j:k:g:o:t:d:D:n:u:T:c:p:s:l:1:2:3:4:iIbw:OMS";
26 #endif
27
28 static char *const SEPARATOR = ":";
29
30 static const struct option long_options[] =
31 {
32 {"advice-disable", no_argument, NULL, IDX_ADVICE_DISABLE},
33 {"attack-mode", required_argument, NULL, IDX_ATTACK_MODE},
34 {"backend-devices", required_argument, NULL, IDX_BACKEND_DEVICES},
35 {"backend-ignore-cuda", no_argument, NULL, IDX_BACKEND_IGNORE_CUDA},
36 {"backend-ignore-hip", no_argument, NULL, IDX_BACKEND_IGNORE_HIP},
37 {"backend-ignore-opencl", no_argument, NULL, IDX_BACKEND_IGNORE_OPENCL},
38 {"backend-info", no_argument, NULL, IDX_BACKEND_INFO},
39 {"backend-vector-width", required_argument, NULL, IDX_BACKEND_VECTOR_WIDTH},
40 {"benchmark-all", no_argument, NULL, IDX_BENCHMARK_ALL},
41 {"benchmark", no_argument, NULL, IDX_BENCHMARK},
42 {"bitmap-max", required_argument, NULL, IDX_BITMAP_MAX},
43 {"bitmap-min", required_argument, NULL, IDX_BITMAP_MIN},
44 {"cpu-affinity", required_argument, NULL, IDX_CPU_AFFINITY},
45 {"custom-charset1", required_argument, NULL, IDX_CUSTOM_CHARSET_1},
46 {"custom-charset2", required_argument, NULL, IDX_CUSTOM_CHARSET_2},
47 {"custom-charset3", required_argument, NULL, IDX_CUSTOM_CHARSET_3},
48 {"custom-charset4", required_argument, NULL, IDX_CUSTOM_CHARSET_4},
49 {"debug-file", required_argument, NULL, IDX_DEBUG_FILE},
50 {"debug-mode", required_argument, NULL, IDX_DEBUG_MODE},
51 {"deprecated-check-disable", no_argument, NULL, IDX_DEPRECATED_CHECK_DISABLE},
52 {"encoding-from", required_argument, NULL, IDX_ENCODING_FROM},
53 {"encoding-to", required_argument, NULL, IDX_ENCODING_TO},
54 {"example-hashes", no_argument, NULL, IDX_HASH_INFO}, // alias of hash-info
55 {"force", no_argument, NULL, IDX_FORCE},
56 {"generate-rules-func-max", required_argument, NULL, IDX_RP_GEN_FUNC_MAX},
57 {"generate-rules-func-min", required_argument, NULL, IDX_RP_GEN_FUNC_MIN},
58 {"generate-rules-func-sel", required_argument, NULL, IDX_RP_GEN_FUNC_SEL},
59 {"generate-rules", required_argument, NULL, IDX_RP_GEN},
60 {"generate-rules-seed", required_argument, NULL, IDX_RP_GEN_SEED},
61 {"hwmon-disable", no_argument, NULL, IDX_HWMON_DISABLE},
62 {"hwmon-temp-abort", required_argument, NULL, IDX_HWMON_TEMP_ABORT},
63 {"hash-info", no_argument, NULL, IDX_HASH_INFO},
64 {"hash-type", required_argument, NULL, IDX_HASH_MODE},
65 {"hccapx-message-pair", required_argument, NULL, IDX_HCCAPX_MESSAGE_PAIR},
66 {"help", no_argument, NULL, IDX_HELP},
67 {"hex-charset", no_argument, NULL, IDX_HEX_CHARSET},
68 {"hex-salt", no_argument, NULL, IDX_HEX_SALT},
69 {"hex-wordlist", no_argument, NULL, IDX_HEX_WORDLIST},
70 {"hook-threads", required_argument, NULL, IDX_HOOK_THREADS},
71 {"identify", no_argument, NULL, IDX_IDENTIFY},
72 {"increment-max", required_argument, NULL, IDX_INCREMENT_MAX},
73 {"increment-min", required_argument, NULL, IDX_INCREMENT_MIN},
74 {"increment", no_argument, NULL, IDX_INCREMENT},
75 {"induction-dir", required_argument, NULL, IDX_INDUCTION_DIR},
76 {"keep-guessing", no_argument, NULL, IDX_KEEP_GUESSING},
77 {"kernel-accel", required_argument, NULL, IDX_KERNEL_ACCEL},
78 {"kernel-loops", required_argument, NULL, IDX_KERNEL_LOOPS},
79 {"kernel-threads", required_argument, NULL, IDX_KERNEL_THREADS},
80 {"keyboard-layout-mapping", required_argument, NULL, IDX_KEYBOARD_LAYOUT_MAPPING},
81 {"keyspace", no_argument, NULL, IDX_KEYSPACE},
82 {"left", no_argument, NULL, IDX_LEFT},
83 {"limit", required_argument, NULL, IDX_LIMIT},
84 {"logfile-disable", no_argument, NULL, IDX_LOGFILE_DISABLE},
85 {"loopback", no_argument, NULL, IDX_LOOPBACK},
86 {"machine-readable", no_argument, NULL, IDX_MACHINE_READABLE},
87 {"markov-classic", no_argument, NULL, IDX_MARKOV_CLASSIC},
88 {"markov-disable", no_argument, NULL, IDX_MARKOV_DISABLE},
89 {"markov-hcstat2", required_argument, NULL, IDX_MARKOV_HCSTAT2},
90 {"markov-inverse", no_argument, NULL, IDX_MARKOV_INVERSE},
91 {"markov-threshold", required_argument, NULL, IDX_MARKOV_THRESHOLD},
92 {"nonce-error-corrections", required_argument, NULL, IDX_NONCE_ERROR_CORRECTIONS},
93 {"opencl-device-types", required_argument, NULL, IDX_OPENCL_DEVICE_TYPES},
94 {"optimized-kernel-enable", no_argument, NULL, IDX_OPTIMIZED_KERNEL_ENABLE},
95 {"multiply-accel-disable", no_argument, NULL, IDX_MULTIPLY_ACCEL_DISABLE},
96 {"outfile-autohex-disable", no_argument, NULL, IDX_OUTFILE_AUTOHEX_DISABLE},
97 {"outfile-check-dir", required_argument, NULL, IDX_OUTFILE_CHECK_DIR},
98 {"outfile-check-timer", required_argument, NULL, IDX_OUTFILE_CHECK_TIMER},
99 {"outfile-format", required_argument, NULL, IDX_OUTFILE_FORMAT},
100 {"outfile", required_argument, NULL, IDX_OUTFILE},
101 {"potfile-disable", no_argument, NULL, IDX_POTFILE_DISABLE},
102 {"potfile-path", required_argument, NULL, IDX_POTFILE_PATH},
103 {"progress-only", no_argument, NULL, IDX_PROGRESS_ONLY},
104 {"quiet", no_argument, NULL, IDX_QUIET},
105 {"remove", no_argument, NULL, IDX_REMOVE},
106 {"remove-timer", required_argument, NULL, IDX_REMOVE_TIMER},
107 {"restore-disable", no_argument, NULL, IDX_RESTORE_DISABLE},
108 {"restore-file-path", required_argument, NULL, IDX_RESTORE_FILE_PATH},
109 {"restore", no_argument, NULL, IDX_RESTORE},
110 {"rule-left", required_argument, NULL, IDX_RULE_BUF_L},
111 {"rule-right", required_argument, NULL, IDX_RULE_BUF_R},
112 {"rules-file", required_argument, NULL, IDX_RP_FILE},
113 {"runtime", required_argument, NULL, IDX_RUNTIME},
114 {"scrypt-tmto", required_argument, NULL, IDX_SCRYPT_TMTO},
115 {"segment-size", required_argument, NULL, IDX_SEGMENT_SIZE},
116 {"self-test-disable", no_argument, NULL, IDX_SELF_TEST_DISABLE},
117 {"separator", required_argument, NULL, IDX_SEPARATOR},
118 {"seperator", required_argument, NULL, IDX_SEPARATOR},
119 {"session", required_argument, NULL, IDX_SESSION},
120 {"show", no_argument, NULL, IDX_SHOW},
121 {"skip", required_argument, NULL, IDX_SKIP},
122 {"slow-candidates", no_argument, NULL, IDX_SLOW_CANDIDATES},
123 {"speed-only", no_argument, NULL, IDX_SPEED_ONLY},
124 {"spin-damp", required_argument, NULL, IDX_SPIN_DAMP},
125 {"status", no_argument, NULL, IDX_STATUS},
126 {"status-json", no_argument, NULL, IDX_STATUS_JSON},
127 {"status-timer", required_argument, NULL, IDX_STATUS_TIMER},
128 {"stdout", no_argument, NULL, IDX_STDOUT_FLAG},
129 {"stdin-timeout-abort", required_argument, NULL, IDX_STDIN_TIMEOUT_ABORT},
130 {"truecrypt-keyfiles", required_argument, NULL, IDX_TRUECRYPT_KEYFILES},
131 {"username", no_argument, NULL, IDX_USERNAME},
132 {"veracrypt-keyfiles", required_argument, NULL, IDX_VERACRYPT_KEYFILES},
133 {"veracrypt-pim-start", required_argument, NULL, IDX_VERACRYPT_PIM_START},
134 {"veracrypt-pim-stop", required_argument, NULL, IDX_VERACRYPT_PIM_STOP},
135 {"version", no_argument, NULL, IDX_VERSION},
136 {"wordlist-autohex-disable", no_argument, NULL, IDX_WORDLIST_AUTOHEX_DISABLE},
137 {"workload-profile", required_argument, NULL, IDX_WORKLOAD_PROFILE},
138 #ifdef WITH_BRAIN
139 {"brain-client", no_argument, NULL, IDX_BRAIN_CLIENT},
140 {"brain-client-features", required_argument, NULL, IDX_BRAIN_CLIENT_FEATURES},
141 {"brain-server", no_argument, NULL, IDX_BRAIN_SERVER},
142 {"brain-server-timer", required_argument, NULL, IDX_BRAIN_SERVER_TIMER},
143 {"brain-host", required_argument, NULL, IDX_BRAIN_HOST},
144 {"brain-port", required_argument, NULL, IDX_BRAIN_PORT},
145 {"brain-password", required_argument, NULL, IDX_BRAIN_PASSWORD},
146 {"brain-session", required_argument, NULL, IDX_BRAIN_SESSION},
147 {"brain-session-whitelist", required_argument, NULL, IDX_BRAIN_SESSION_WHITELIST},
148 #endif
149 {NULL, 0, NULL, 0 }
150 };
151
152 static const char *const ENCODING_FROM = "utf-8";
153 static const char *const ENCODING_TO = "utf-8";
154
155 static const char *const RULE_BUF_R = ":";
156 static const char *const RULE_BUF_L = ":";
157
158 static const char *const DEF_MASK_CS_1 = "?l?d?u";
159 static const char *const DEF_MASK_CS_2 = "?l?d";
160 static const char *const DEF_MASK_CS_3 = "?l?d*!$@_";
161
user_options_init(hashcat_ctx_t * hashcat_ctx)162 int user_options_init (hashcat_ctx_t *hashcat_ctx)
163 {
164 user_options_t *user_options = hashcat_ctx->user_options;
165
166 user_options->advice_disable = ADVICE_DISABLE;
167 user_options->attack_mode = ATTACK_MODE;
168 user_options->autodetect = AUTODETECT;
169 user_options->backend_devices = NULL;
170 user_options->backend_ignore_cuda = BACKEND_IGNORE_CUDA;
171 user_options->backend_ignore_hip = BACKEND_IGNORE_HIP;
172 user_options->backend_ignore_opencl = BACKEND_IGNORE_OPENCL;
173 user_options->backend_info = BACKEND_INFO;
174 user_options->backend_vector_width = BACKEND_VECTOR_WIDTH;
175 user_options->benchmark_all = BENCHMARK_ALL;
176 user_options->benchmark = BENCHMARK;
177 user_options->bitmap_max = BITMAP_MAX;
178 user_options->bitmap_min = BITMAP_MIN;
179 #ifdef WITH_BRAIN
180 user_options->brain_client = BRAIN_CLIENT;
181 user_options->brain_client_features = BRAIN_CLIENT_FEATURES;
182 user_options->brain_host = NULL;
183 user_options->brain_port = BRAIN_PORT;
184 user_options->brain_server = BRAIN_SERVER;
185 user_options->brain_server_timer = BRAIN_SERVER_TIMER;
186 user_options->brain_session = BRAIN_SESSION;
187 user_options->brain_session_whitelist = NULL;
188 #endif
189 user_options->cpu_affinity = NULL;
190 user_options->custom_charset_1 = NULL;
191 user_options->custom_charset_2 = NULL;
192 user_options->custom_charset_3 = NULL;
193 user_options->custom_charset_4 = NULL;
194 user_options->debug_file = NULL;
195 user_options->debug_mode = DEBUG_MODE;
196 user_options->deprecated_check_disable = DEPRECATED_CHECK_DISABLE;
197 user_options->encoding_from = ENCODING_FROM;
198 user_options->encoding_to = ENCODING_TO;
199 user_options->force = FORCE;
200 user_options->hwmon_disable = HWMON_DISABLE;
201 user_options->hwmon_temp_abort = HWMON_TEMP_ABORT;
202 user_options->hash_info = HASH_INFO;
203 user_options->hash_mode = HASH_MODE;
204 user_options->hccapx_message_pair = HCCAPX_MESSAGE_PAIR;
205 user_options->hex_charset = HEX_CHARSET;
206 user_options->hex_salt = HEX_SALT;
207 user_options->hex_wordlist = HEX_WORDLIST;
208 user_options->hook_threads = HOOK_THREADS;
209 user_options->identify = IDENTIFY;
210 user_options->increment = INCREMENT;
211 user_options->increment_max = INCREMENT_MAX;
212 user_options->increment_min = INCREMENT_MIN;
213 user_options->induction_dir = NULL;
214 user_options->keep_guessing = KEEP_GUESSING;
215 user_options->kernel_accel = KERNEL_ACCEL;
216 user_options->kernel_loops = KERNEL_LOOPS;
217 user_options->kernel_threads = KERNEL_THREADS;
218 user_options->keyboard_layout_mapping = NULL;
219 user_options->keyspace = KEYSPACE;
220 user_options->left = LEFT;
221 user_options->limit = LIMIT;
222 user_options->logfile_disable = LOGFILE_DISABLE;
223 user_options->loopback = LOOPBACK;
224 user_options->machine_readable = MACHINE_READABLE;
225 user_options->markov_classic = MARKOV_CLASSIC;
226 user_options->markov_disable = MARKOV_DISABLE;
227 user_options->markov_hcstat2 = NULL;
228 user_options->markov_inverse = MARKOV_INVERSE;
229 user_options->markov_threshold = MARKOV_THRESHOLD;
230 user_options->nonce_error_corrections = NONCE_ERROR_CORRECTIONS;
231 user_options->opencl_device_types = NULL;
232 user_options->optimized_kernel_enable = OPTIMIZED_KERNEL_ENABLE;
233 user_options->multiply_accel_disable = MULTIPLY_ACCEL_DISABLE;
234 user_options->outfile_autohex = OUTFILE_AUTOHEX;
235 user_options->outfile_check_dir = NULL;
236 user_options->outfile_check_timer = OUTFILE_CHECK_TIMER;
237 user_options->outfile_format = OUTFILE_FORMAT;
238 user_options->outfile = NULL;
239 user_options->potfile_disable = POTFILE_DISABLE;
240 user_options->potfile_path = NULL;
241 user_options->progress_only = PROGRESS_ONLY;
242 user_options->quiet = QUIET;
243 user_options->remove = REMOVE;
244 user_options->remove_timer = REMOVE_TIMER;
245 user_options->restore_disable = RESTORE_DISABLE;
246 user_options->restore_file_path = NULL;
247 user_options->restore = RESTORE;
248 user_options->restore_timer = RESTORE_TIMER;
249 user_options->rp_gen_func_max = RP_GEN_FUNC_MAX;
250 user_options->rp_gen_func_min = RP_GEN_FUNC_MIN;
251 user_options->rp_gen_func_sel = NULL;
252 user_options->rp_gen = RP_GEN;
253 user_options->rp_gen_seed = RP_GEN_SEED;
254 user_options->rule_buf_l = RULE_BUF_L;
255 user_options->rule_buf_r = RULE_BUF_R;
256 user_options->runtime = RUNTIME;
257 user_options->scrypt_tmto = SCRYPT_TMTO;
258 user_options->segment_size = SEGMENT_SIZE;
259 user_options->self_test_disable = SELF_TEST_DISABLE;
260 user_options->separator = SEPARATOR;
261 user_options->session = PROGNAME;
262 user_options->show = SHOW;
263 user_options->skip = SKIP;
264 user_options->slow_candidates = SLOW_CANDIDATES;
265 user_options->speed_only = SPEED_ONLY;
266 user_options->spin_damp = SPIN_DAMP;
267 user_options->status = STATUS;
268 user_options->status_json = STATUS_JSON;
269 user_options->status_timer = STATUS_TIMER;
270 user_options->stdin_timeout_abort = STDIN_TIMEOUT_ABORT;
271 user_options->stdout_flag = STDOUT_FLAG;
272 user_options->truecrypt_keyfiles = NULL;
273 user_options->usage = USAGE;
274 user_options->username = USERNAME;
275 user_options->veracrypt_keyfiles = NULL;
276 user_options->veracrypt_pim_start = VERACRYPT_PIM_START;
277 user_options->veracrypt_pim_stop = VERACRYPT_PIM_STOP;
278 user_options->version = VERSION;
279 user_options->wordlist_autohex_disable = WORDLIST_AUTOHEX_DISABLE;
280 user_options->workload_profile = WORKLOAD_PROFILE;
281 user_options->rp_files_cnt = 0;
282 user_options->rp_files = (char **) hccalloc (256, sizeof (char *));
283 user_options->hc_bin = PROGNAME;
284 user_options->hc_argc = 0;
285 user_options->hc_argv = NULL;
286
287 return 0;
288 }
289
user_options_destroy(hashcat_ctx_t * hashcat_ctx)290 void user_options_destroy (hashcat_ctx_t *hashcat_ctx)
291 {
292 user_options_t *user_options = hashcat_ctx->user_options;
293
294 hcfree (user_options->rp_files);
295
296 //do not reset this, it might be used from main.c
297 //memset (user_options, 0, sizeof (user_options_t));
298 }
299
user_options_getopt(hashcat_ctx_t * hashcat_ctx,int argc,char ** argv)300 int user_options_getopt (hashcat_ctx_t *hashcat_ctx, int argc, char **argv)
301 {
302 user_options_t *user_options = hashcat_ctx->user_options;
303
304 int c = -1;
305
306 int option_index;
307
308 optind = 1;
309 optopt = 0;
310
311 option_index = 0;
312
313 while ((c = getopt_long (argc, argv, short_options, long_options, &option_index)) != -1)
314 {
315 switch (c)
316 {
317 case IDX_REMOVE_TIMER:
318 case IDX_DEBUG_MODE:
319 case IDX_SKIP:
320 case IDX_LIMIT:
321 case IDX_STATUS_TIMER:
322 case IDX_HASH_MODE:
323 case IDX_RUNTIME:
324 case IDX_ATTACK_MODE:
325 case IDX_RP_GEN:
326 case IDX_RP_GEN_FUNC_MIN:
327 case IDX_RP_GEN_FUNC_MAX:
328 case IDX_RP_GEN_SEED:
329 case IDX_MARKOV_THRESHOLD:
330 case IDX_OUTFILE_CHECK_TIMER:
331 case IDX_BACKEND_VECTOR_WIDTH:
332 case IDX_WORKLOAD_PROFILE:
333 case IDX_KERNEL_ACCEL:
334 case IDX_KERNEL_LOOPS:
335 case IDX_KERNEL_THREADS:
336 case IDX_SPIN_DAMP:
337 case IDX_HWMON_TEMP_ABORT:
338 case IDX_HCCAPX_MESSAGE_PAIR:
339 case IDX_NONCE_ERROR_CORRECTIONS:
340 case IDX_VERACRYPT_PIM_START:
341 case IDX_VERACRYPT_PIM_STOP:
342 case IDX_SEGMENT_SIZE:
343 case IDX_SCRYPT_TMTO:
344 case IDX_BITMAP_MIN:
345 case IDX_BITMAP_MAX:
346 case IDX_INCREMENT_MIN:
347 case IDX_INCREMENT_MAX:
348 case IDX_HOOK_THREADS:
349 #ifdef WITH_BRAIN
350 case IDX_BRAIN_PORT:
351 #endif
352
353 if (hc_string_is_digit (optarg) == false)
354 {
355 event_log_error (hashcat_ctx, "The specified parameter cannot use '%s' as a value - must be a number.", optarg);
356
357 return -1;
358 }
359
360 break;
361
362 case '?':
363 {
364 event_log_error (hashcat_ctx, "Invalid argument specified.");
365
366 return -1;
367 }
368 }
369 }
370
371 optind = 1;
372 optopt = 0;
373
374 option_index = 0;
375
376 while ((c = getopt_long (argc, argv, short_options, long_options, &option_index)) != -1)
377 {
378 switch (c)
379 {
380 case IDX_HELP: user_options->usage = true; break;
381 case IDX_VERSION: user_options->version = true; break;
382 case IDX_RESTORE: user_options->restore = true; break;
383 case IDX_QUIET: user_options->quiet = true; break;
384 case IDX_SHOW: user_options->show = true; break;
385 case IDX_DEPRECATED_CHECK_DISABLE: user_options->deprecated_check_disable = true; break;
386 case IDX_LEFT: user_options->left = true; break;
387 case IDX_ADVICE_DISABLE: user_options->advice_disable = true; break;
388 case IDX_USERNAME: user_options->username = true; break;
389 case IDX_REMOVE: user_options->remove = true; break;
390 case IDX_REMOVE_TIMER: user_options->remove_timer = hc_strtoul (optarg, NULL, 10);
391 user_options->remove_timer_chgd = true; break;
392 case IDX_POTFILE_DISABLE: user_options->potfile_disable = true; break;
393 case IDX_POTFILE_PATH: user_options->potfile_path = optarg; break;
394 case IDX_DEBUG_MODE: user_options->debug_mode = hc_strtoul (optarg, NULL, 10); break;
395 case IDX_DEBUG_FILE: user_options->debug_file = optarg; break;
396 case IDX_ENCODING_FROM: user_options->encoding_from = optarg; break;
397 case IDX_ENCODING_TO: user_options->encoding_to = optarg; break;
398 case IDX_INDUCTION_DIR: user_options->induction_dir = optarg; break;
399 case IDX_OUTFILE_CHECK_DIR: user_options->outfile_check_dir = optarg; break;
400 case IDX_HASH_INFO: user_options->hash_info = true; break;
401 case IDX_FORCE: user_options->force = true; break;
402 case IDX_SELF_TEST_DISABLE: user_options->self_test_disable = true; break;
403 case IDX_SKIP: user_options->skip = hc_strtoull (optarg, NULL, 10);
404 user_options->skip_chgd = true; break;
405 case IDX_LIMIT: user_options->limit = hc_strtoull (optarg, NULL, 10);
406 user_options->limit_chgd = true; break;
407 case IDX_KEEP_GUESSING: user_options->keep_guessing = true; break;
408 case IDX_KEYSPACE: user_options->keyspace = true; break;
409 case IDX_BENCHMARK: user_options->benchmark = true; break;
410 case IDX_BENCHMARK_ALL: user_options->benchmark_all = true; break;
411 case IDX_STDOUT_FLAG: user_options->stdout_flag = true; break;
412 case IDX_STDIN_TIMEOUT_ABORT: user_options->stdin_timeout_abort = hc_strtoul (optarg, NULL, 10);
413 user_options->stdin_timeout_abort_chgd = true; break;
414 case IDX_IDENTIFY: user_options->identify = true; break;
415 case IDX_SPEED_ONLY: user_options->speed_only = true; break;
416 case IDX_PROGRESS_ONLY: user_options->progress_only = true; break;
417 case IDX_RESTORE_DISABLE: user_options->restore_disable = true; break;
418 case IDX_RESTORE_FILE_PATH: user_options->restore_file_path = optarg; break;
419 case IDX_STATUS: user_options->status = true; break;
420 case IDX_STATUS_JSON: user_options->status_json = true; break;
421 case IDX_STATUS_TIMER: user_options->status_timer = hc_strtoul (optarg, NULL, 10); break;
422 case IDX_MACHINE_READABLE: user_options->machine_readable = true; break;
423 case IDX_LOOPBACK: user_options->loopback = true; break;
424 case IDX_SESSION: user_options->session = optarg; break;
425 case IDX_HASH_MODE: user_options->hash_mode = hc_strtoul (optarg, NULL, 10);
426 user_options->hash_mode_chgd = true; break;
427 case IDX_RUNTIME: user_options->runtime = hc_strtoul (optarg, NULL, 10);
428 user_options->runtime_chgd = true; break;
429 case IDX_ATTACK_MODE: user_options->attack_mode = hc_strtoul (optarg, NULL, 10);
430 user_options->attack_mode_chgd = true; break;
431 case IDX_RP_FILE: user_options->rp_files[user_options->rp_files_cnt++] = optarg; break;
432 case IDX_RP_GEN: user_options->rp_gen = hc_strtoul (optarg, NULL, 10); break;
433 case IDX_RP_GEN_FUNC_MIN: user_options->rp_gen_func_min = hc_strtoul (optarg, NULL, 10); break;
434 case IDX_RP_GEN_FUNC_MAX: user_options->rp_gen_func_max = hc_strtoul (optarg, NULL, 10); break;
435 case IDX_RP_GEN_FUNC_SEL: user_options->rp_gen_func_sel = optarg; break;
436 case IDX_RP_GEN_SEED: user_options->rp_gen_seed = hc_strtoul (optarg, NULL, 10);
437 user_options->rp_gen_seed_chgd = true; break;
438 case IDX_RULE_BUF_L: user_options->rule_buf_l = optarg; break;
439 case IDX_RULE_BUF_R: user_options->rule_buf_r = optarg; break;
440 case IDX_MARKOV_DISABLE: user_options->markov_disable = true; break;
441 case IDX_MARKOV_CLASSIC: user_options->markov_classic = true; break;
442 case IDX_MARKOV_INVERSE: user_options->markov_inverse = true; break;
443 case IDX_MARKOV_THRESHOLD: user_options->markov_threshold = hc_strtoul (optarg, NULL, 10); break;
444 case IDX_MARKOV_HCSTAT2: user_options->markov_hcstat2 = optarg; break;
445 case IDX_OUTFILE: user_options->outfile = optarg; break;
446 case IDX_OUTFILE_FORMAT: user_options->outfile_format = outfile_format_parse (optarg);
447 user_options->outfile_format_chgd = true; break;
448 case IDX_OUTFILE_AUTOHEX_DISABLE: user_options->outfile_autohex = false; break;
449 case IDX_OUTFILE_CHECK_TIMER: user_options->outfile_check_timer = hc_strtoul (optarg, NULL, 10); break;
450 case IDX_WORDLIST_AUTOHEX_DISABLE: user_options->wordlist_autohex_disable = true; break;
451 case IDX_HEX_CHARSET: user_options->hex_charset = true; break;
452 case IDX_HEX_SALT: user_options->hex_salt = true; break;
453 case IDX_HEX_WORDLIST: user_options->hex_wordlist = true; break;
454 case IDX_CPU_AFFINITY: user_options->cpu_affinity = optarg; break;
455 case IDX_BACKEND_IGNORE_CUDA: user_options->backend_ignore_cuda = true; break;
456 case IDX_BACKEND_IGNORE_HIP: user_options->backend_ignore_hip = true; break;
457 case IDX_BACKEND_IGNORE_OPENCL: user_options->backend_ignore_opencl = true; break;
458 case IDX_BACKEND_INFO: user_options->backend_info = true; break;
459 case IDX_BACKEND_DEVICES: user_options->backend_devices = optarg; break;
460 case IDX_BACKEND_VECTOR_WIDTH: user_options->backend_vector_width = hc_strtoul (optarg, NULL, 10);
461 user_options->backend_vector_width_chgd = true; break;
462 case IDX_OPENCL_DEVICE_TYPES: user_options->opencl_device_types = optarg; break;
463 case IDX_OPTIMIZED_KERNEL_ENABLE: user_options->optimized_kernel_enable = true; break;
464 case IDX_MULTIPLY_ACCEL_DISABLE: user_options->multiply_accel_disable = true; break;
465 case IDX_WORKLOAD_PROFILE: user_options->workload_profile = hc_strtoul (optarg, NULL, 10);
466 user_options->workload_profile_chgd = true; break;
467 case IDX_KERNEL_ACCEL: user_options->kernel_accel = hc_strtoul (optarg, NULL, 10);
468 user_options->kernel_accel_chgd = true; break;
469 case IDX_KERNEL_LOOPS: user_options->kernel_loops = hc_strtoul (optarg, NULL, 10);
470 user_options->kernel_loops_chgd = true; break;
471 case IDX_KERNEL_THREADS: user_options->kernel_threads = hc_strtoul (optarg, NULL, 10);
472 user_options->kernel_threads_chgd = true; break;
473 case IDX_SPIN_DAMP: user_options->spin_damp = hc_strtoul (optarg, NULL, 10);
474 user_options->spin_damp_chgd = true; break;
475 case IDX_HWMON_DISABLE: user_options->hwmon_disable = true; break;
476 case IDX_HWMON_TEMP_ABORT: user_options->hwmon_temp_abort = hc_strtoul (optarg, NULL, 10); break;
477 case IDX_LOGFILE_DISABLE: user_options->logfile_disable = true; break;
478 case IDX_HCCAPX_MESSAGE_PAIR: user_options->hccapx_message_pair = hc_strtoul (optarg, NULL, 10);
479 user_options->hccapx_message_pair_chgd = true; break;
480 case IDX_NONCE_ERROR_CORRECTIONS: user_options->nonce_error_corrections = hc_strtoul (optarg, NULL, 10);
481 user_options->nonce_error_corrections_chgd = true; break;
482 case IDX_KEYBOARD_LAYOUT_MAPPING: user_options->keyboard_layout_mapping = optarg; break;
483 case IDX_TRUECRYPT_KEYFILES: user_options->truecrypt_keyfiles = optarg; break;
484 case IDX_VERACRYPT_KEYFILES: user_options->veracrypt_keyfiles = optarg; break;
485 case IDX_VERACRYPT_PIM_START: user_options->veracrypt_pim_start = hc_strtoul (optarg, NULL, 10);
486 user_options->veracrypt_pim_start_chgd = true; break;
487 case IDX_VERACRYPT_PIM_STOP: user_options->veracrypt_pim_stop = hc_strtoul (optarg, NULL, 10);
488 user_options->veracrypt_pim_stop_chgd = true; break;
489 case IDX_SEGMENT_SIZE: user_options->segment_size = hc_strtoul (optarg, NULL, 10);
490 user_options->segment_size_chgd = true; break;
491 case IDX_SCRYPT_TMTO: user_options->scrypt_tmto = hc_strtoul (optarg, NULL, 10);
492 user_options->scrypt_tmto_chgd = true; break;
493 case IDX_SEPARATOR: user_options->separator = optarg;
494 user_options->separator_chgd = true; break;
495 case IDX_BITMAP_MIN: user_options->bitmap_min = hc_strtoul (optarg, NULL, 10); break;
496 case IDX_BITMAP_MAX: user_options->bitmap_max = hc_strtoul (optarg, NULL, 10); break;
497 case IDX_HOOK_THREADS: user_options->hook_threads = hc_strtoul (optarg, NULL, 10); break;
498 case IDX_INCREMENT: user_options->increment = true; break;
499 case IDX_INCREMENT_MIN: user_options->increment_min = hc_strtoul (optarg, NULL, 10);
500 user_options->increment_min_chgd = true; break;
501 case IDX_INCREMENT_MAX: user_options->increment_max = hc_strtoul (optarg, NULL, 10);
502 user_options->increment_max_chgd = true; break;
503 case IDX_CUSTOM_CHARSET_1: user_options->custom_charset_1 = optarg; break;
504 case IDX_CUSTOM_CHARSET_2: user_options->custom_charset_2 = optarg; break;
505 case IDX_CUSTOM_CHARSET_3: user_options->custom_charset_3 = optarg; break;
506 case IDX_CUSTOM_CHARSET_4: user_options->custom_charset_4 = optarg; break;
507 case IDX_SLOW_CANDIDATES: user_options->slow_candidates = true; break;
508 #ifdef WITH_BRAIN
509 case IDX_BRAIN_CLIENT: user_options->brain_client = true; break;
510 case IDX_BRAIN_CLIENT_FEATURES: user_options->brain_client_features = hc_strtoul (optarg, NULL, 10); break;
511 case IDX_BRAIN_SERVER: user_options->brain_server = true; break;
512 case IDX_BRAIN_SERVER_TIMER: user_options->brain_server_timer = hc_strtoul (optarg, NULL, 10);
513 user_options->brain_server_timer_chgd = true; break;
514 case IDX_BRAIN_PASSWORD: user_options->brain_password = optarg;
515 user_options->brain_password_chgd = true; break;
516 case IDX_BRAIN_HOST: user_options->brain_host = optarg;
517 user_options->brain_host_chgd = true; break;
518 case IDX_BRAIN_PORT: user_options->brain_port = hc_strtoul (optarg, NULL, 10);
519 user_options->brain_port_chgd = true; break;
520 case IDX_BRAIN_SESSION: user_options->brain_session = hc_strtoul (optarg, NULL, 16); break;
521 case IDX_BRAIN_SESSION_WHITELIST: user_options->brain_session_whitelist = optarg; break;
522 #endif
523 }
524 }
525
526 user_options->hc_bin = argv[0];
527
528 user_options->hc_argc = argc - optind;
529 user_options->hc_argv = argv + optind;
530
531 return 0;
532 }
533
user_options_sanity(hashcat_ctx_t * hashcat_ctx)534 int user_options_sanity (hashcat_ctx_t *hashcat_ctx)
535 {
536 user_options_t *user_options = hashcat_ctx->user_options;
537
538 if (user_options->hc_argc < 0)
539 {
540 event_log_error (hashcat_ctx, "hc_argc %d is invalid.", user_options->hc_argc);
541
542 return -1;
543 }
544
545 if (user_options->hc_argv == NULL)
546 {
547 event_log_error (hashcat_ctx, "hc_argv is NULL.");
548
549 return -1;
550 }
551
552 #ifdef WITH_BRAIN
553 if ((user_options->brain_client == true) && (user_options->brain_server == true))
554 {
555 event_log_error (hashcat_ctx, "Can not have --brain-client and --brain-server at the same time");
556
557 return -1;
558 }
559
560 if ((user_options->brain_client_features < 1) || (user_options->brain_client_features > 3))
561 {
562 event_log_error (hashcat_ctx, "Invalid --brain-client-feature argument");
563
564 return -1;
565 }
566
567 if ((user_options->brain_client == true) && (user_options->brain_password_chgd == false))
568 {
569 event_log_error (hashcat_ctx, "Brain clients need to set --brain-password");
570
571 return -1;
572 }
573
574 if (user_options->brain_server_timer_chgd)
575 {
576 if (user_options->brain_server == false)
577 {
578 event_log_error (hashcat_ctx, "The --brain-server-timer flag requires --brain-server.");
579
580 return -1;
581 }
582
583 if (user_options->brain_server_timer != 0) // special case (no intermediate dumps)
584 {
585 if (user_options->brain_server_timer < 60)
586 {
587 event_log_error (hashcat_ctx, "Brain server backup timer must be at least 60 seconds.");
588
589 return -1;
590 }
591 }
592 }
593 #endif
594
595 if (user_options->separator_chgd == true)
596 {
597 if (strlen (user_options->separator) != 1)
598 {
599 event_log_error (hashcat_ctx, "Separator length has to be exactly 1 byte.");
600
601 return -1;
602 }
603 }
604
605 if (user_options->slow_candidates == true)
606 {
607 if ((user_options->attack_mode != ATTACK_MODE_STRAIGHT)
608 && (user_options->attack_mode != ATTACK_MODE_COMBI)
609 && (user_options->attack_mode != ATTACK_MODE_BF))
610 {
611 event_log_error (hashcat_ctx, "Invalid attack mode (-a) value specified in slow-candidates mode.");
612
613 return -1;
614 }
615 }
616 #ifdef WITH_BRAIN
617 else if (user_options->brain_client == true)
618 {
619 if ((user_options->attack_mode != ATTACK_MODE_STRAIGHT)
620 && (user_options->attack_mode != ATTACK_MODE_COMBI)
621 && (user_options->attack_mode != ATTACK_MODE_BF))
622 {
623 event_log_error (hashcat_ctx, "Invalid attack mode (-a) value specified in brain-client mode.");
624
625 return -1;
626 }
627 }
628 #endif
629 else
630 {
631 if ((user_options->attack_mode != ATTACK_MODE_STRAIGHT)
632 && (user_options->attack_mode != ATTACK_MODE_COMBI)
633 && (user_options->attack_mode != ATTACK_MODE_BF)
634 && (user_options->attack_mode != ATTACK_MODE_HYBRID1)
635 && (user_options->attack_mode != ATTACK_MODE_HYBRID2)
636 && (user_options->attack_mode != ATTACK_MODE_ASSOCIATION)
637 && (user_options->attack_mode != ATTACK_MODE_NONE))
638 {
639 event_log_error (hashcat_ctx, "Invalid attack mode (-a) value specified.");
640
641 return -1;
642 }
643 }
644
645 if (user_options->hccapx_message_pair_chgd == true)
646 {
647 if (user_options->remove == true)
648 {
649 event_log_error (hashcat_ctx, "Combining --remove with --hccapx-message-pair is not allowed.");
650
651 return -1;
652 }
653
654 if (user_options->hccapx_message_pair >= 6)
655 {
656 event_log_error (hashcat_ctx, "Invalid --hccapx-message-pair value specified.");
657
658 return -1;
659 }
660 }
661
662 /*
663 if (user_options->skip_chgd == true && user_options->skip == 0)
664 {
665 event_log_error (hashcat_ctx, "Invalid --skip value specified.");
666
667 return -1;
668 }
669 */
670
671 if (user_options->limit_chgd == true && user_options->limit == 0)
672 {
673 event_log_error (hashcat_ctx, "Invalid --limit value specified.");
674
675 return -1;
676 }
677
678 if (user_options->runtime_chgd == true && user_options->runtime == 0)
679 {
680 event_log_error (hashcat_ctx, "Invalid --runtime value specified.");
681
682 return -1;
683 }
684
685 if (user_options->runtime_chgd == true && user_options->loopback == true)
686 {
687 event_log_error (hashcat_ctx, "Combining --limit with --loopback is not allowed.");
688
689 return -1;
690 }
691
692 if (user_options->hash_mode >= MODULE_HASH_MODES_MAXIMUM)
693 {
694 event_log_error (hashcat_ctx, "Invalid -m (hash type) value specified.");
695
696 return -1;
697 }
698
699 if (user_options->outfile_format == 0)
700 {
701 event_log_error (hashcat_ctx, "Invalid --outfile-format value specified.");
702
703 return -1;
704 }
705
706 if (user_options->left == true)
707 {
708 if (user_options->outfile_format_chgd == true)
709 {
710 if (user_options->outfile_format > 1)
711 {
712 event_log_error (hashcat_ctx, "Combining --outfile-format > 1 with --left is not allowed.");
713
714 return -1;
715 }
716 }
717 }
718
719 if (user_options->show == true)
720 {
721 if (user_options->outfile_format_chgd == true)
722 {
723 if (user_options->outfile_format & OUTFILE_FMT_CRACKPOS)
724 {
725 event_log_error (hashcat_ctx, "Using crack_pos in --outfile-format for --show is not allowed.");
726
727 return -1;
728 }
729
730 if (user_options->outfile_format & OUTFILE_FMT_TIME_ABS)
731 {
732 event_log_error (hashcat_ctx, "Using the absolute timestamp in --outfile-format for --show is not allowed.");
733
734 return -1;
735 }
736
737 if (user_options->outfile_format & OUTFILE_FMT_TIME_REL)
738 {
739 event_log_error (hashcat_ctx, "Using the relative timestamp in --outfile-format for --show is not allowed.");
740
741 return -1;
742 }
743 }
744 }
745
746 if (user_options->increment_min < INCREMENT_MIN)
747 {
748 event_log_error (hashcat_ctx, "Invalid --increment-min value specified.");
749
750 return -1;
751 }
752
753 if (user_options->increment_max > INCREMENT_MAX)
754 {
755 event_log_error (hashcat_ctx, "Invalid --increment-max value specified.");
756
757 return -1;
758 }
759
760 if ((user_options->veracrypt_pim_start_chgd == true) && (user_options->veracrypt_pim_stop_chgd == false))
761 {
762 event_log_error (hashcat_ctx, "The--veracrypt-pim-start option requires --veracrypt-pim-stop as well.");
763
764 return -1;
765 }
766
767 if ((user_options->veracrypt_pim_start_chgd == false) && (user_options->veracrypt_pim_stop_chgd == true))
768 {
769 event_log_error (hashcat_ctx, "The --veracrypt-pim-stop option requires --veracrypt-pim-start as well.");
770
771 return -1;
772 }
773
774 if (user_options->veracrypt_pim_start > user_options->veracrypt_pim_stop)
775 {
776 event_log_error (hashcat_ctx, "Invalid --veracrypt-pim-start value specified.");
777
778 return -1;
779 }
780
781 if (user_options->increment_min > user_options->increment_max)
782 {
783 event_log_error (hashcat_ctx, "Invalid --increment-min value specified - must be >= --increment-max.");
784
785 return -1;
786 }
787
788 if ((user_options->increment == true) && (user_options->progress_only == true))
789 {
790 event_log_error (hashcat_ctx, "Increment is not allowed in combination with --progress-only.");
791
792 return -1;
793 }
794
795 if ((user_options->increment == true) && (user_options->speed_only == true))
796 {
797 event_log_error (hashcat_ctx, "Increment is not allowed in combination with --speed-only.");
798
799 return -1;
800 }
801
802 if ((user_options->increment == true) && (user_options->attack_mode == ATTACK_MODE_STRAIGHT))
803 {
804 event_log_error (hashcat_ctx, "Increment is not allowed in attack mode 0 (straight).");
805
806 return -1;
807 }
808
809 if ((user_options->increment == true) && (user_options->attack_mode == ATTACK_MODE_ASSOCIATION))
810 {
811 event_log_error (hashcat_ctx, "Increment is not allowed in attack mode 9 (association).");
812
813 return -1;
814 }
815
816 if ((user_options->remove == true) && (user_options->attack_mode == ATTACK_MODE_ASSOCIATION))
817 {
818 event_log_error (hashcat_ctx, "Remove is not allowed in attack mode 9 (association).");
819
820 return -1;
821 }
822
823 if ((user_options->increment == false) && (user_options->increment_min_chgd == true))
824 {
825 event_log_error (hashcat_ctx, "Increment-min is only supported when combined with -i/--increment.");
826
827 return -1;
828 }
829
830 if ((user_options->increment == false) && (user_options->increment_max_chgd == true))
831 {
832 event_log_error (hashcat_ctx, "Increment-max is only supported combined with -i/--increment.");
833
834 return -1;
835 }
836
837 if ((user_options->rp_files_cnt > 0) && (user_options->rp_gen > 0))
838 {
839 event_log_error (hashcat_ctx, "Combining -r/--rules-file and -g/--rules-generate is not supported.");
840
841 return -1;
842 }
843
844 if ((user_options->rp_files_cnt > 0) || (user_options->rp_gen > 0))
845 {
846 if ((user_options->attack_mode != ATTACK_MODE_STRAIGHT) && (user_options->attack_mode != ATTACK_MODE_ASSOCIATION))
847 {
848 event_log_error (hashcat_ctx, "Use of -r/--rules-file and -g/--rules-generate requires attack mode 0 or 9.");
849
850 return -1;
851 }
852 }
853
854 if (user_options->bitmap_min > user_options->bitmap_max)
855 {
856 event_log_error (hashcat_ctx, "Invalid --bitmap-min value specified.");
857
858 return -1;
859 }
860
861 if (user_options->rp_gen_func_min > user_options->rp_gen_func_max)
862 {
863 event_log_error (hashcat_ctx, "Invalid --rp-gen-func-min value specified.");
864
865 return -1;
866 }
867
868 if (user_options->kernel_accel_chgd == true)
869 {
870 if (user_options->force == false)
871 {
872 event_log_error (hashcat_ctx, "The manual use of the -n option (or --kernel-accel) is outdated.");
873
874 event_log_warning (hashcat_ctx, "Please consider using the -w option instead.");
875 event_log_warning (hashcat_ctx, "You can use --force to override this, but do not report related errors.");
876 event_log_warning (hashcat_ctx, NULL);
877
878 return -1;
879 }
880
881 if (user_options->kernel_accel < 1)
882 {
883 event_log_error (hashcat_ctx, "Invalid --kernel-accel value specified - must be greater than 0.");
884
885 return -1;
886 }
887
888 if (user_options->kernel_accel > 1024)
889 {
890 event_log_error (hashcat_ctx, "Invalid --kernel-accel value specified - must be <= 1024.");
891
892 return -1;
893 }
894 }
895
896 if (user_options->kernel_loops_chgd == true)
897 {
898 if (user_options->force == false)
899 {
900 event_log_error (hashcat_ctx, "The manual use of the -u option (or --kernel-loops) is outdated.");
901
902 event_log_warning (hashcat_ctx, "Please consider using the -w option instead.");
903 event_log_warning (hashcat_ctx, "You can use --force to override this, but do not report related errors.");
904 event_log_warning (hashcat_ctx, NULL);
905
906 return -1;
907 }
908
909 if (user_options->kernel_loops < 1)
910 {
911 event_log_error (hashcat_ctx, "Invalid kernel-loops specified.");
912
913 return -1;
914 }
915
916 if (user_options->kernel_loops > 1024)
917 {
918 event_log_error (hashcat_ctx, "Invalid kernel-loops specified.");
919
920 return -1;
921 }
922 }
923
924 if (user_options->kernel_threads_chgd == true)
925 {
926 if (user_options->force == false)
927 {
928 event_log_error (hashcat_ctx, "The manual use of the -T option (or --kernel-threads) is outdated.");
929
930 event_log_warning (hashcat_ctx, "You can use --force to override this, but do not report related errors.");
931 event_log_warning (hashcat_ctx, NULL);
932
933 return -1;
934 }
935
936 if (user_options->kernel_threads < 1)
937 {
938 event_log_error (hashcat_ctx, "Invalid kernel-threads specified.");
939
940 return -1;
941 }
942
943 if (user_options->kernel_threads > 1024)
944 {
945 event_log_error (hashcat_ctx, "Invalid kernel-threads specified.");
946
947 return -1;
948 }
949 }
950
951 if ((user_options->workload_profile < 1) || (user_options->workload_profile > 4))
952 {
953 event_log_error (hashcat_ctx, "workload-profile %u is not available.", user_options->workload_profile);
954
955 return -1;
956 }
957
958 if (user_options->backend_vector_width_chgd == true)
959 {
960 if (is_power_of_2 (user_options->backend_vector_width) == false || user_options->backend_vector_width > 16)
961 {
962 event_log_error (hashcat_ctx, "backend-vector-width %u is not allowed.", user_options->backend_vector_width);
963
964 return -1;
965 }
966 }
967
968 if (user_options->show == true || user_options->left == true)
969 {
970 if (user_options->remove == true)
971 {
972 event_log_error (hashcat_ctx, "Mixing --remove not allowed with --show or --left.");
973
974 return -1;
975 }
976
977 if (user_options->potfile_disable == true)
978 {
979 event_log_error (hashcat_ctx, "Mixing --potfile-disable is not allowed with --show or --left.");
980
981 return -1;
982 }
983 }
984
985 if (user_options->show == true)
986 {
987 if (user_options->outfile_autohex == false)
988 {
989 event_log_error (hashcat_ctx, "Mixing --outfile-autohex-disable is not allowed with --show.");
990
991 return -1;
992 }
993 }
994
995 if (user_options->keyspace == true)
996 {
997 if (user_options->show == true)
998 {
999 event_log_error (hashcat_ctx, "Combining --show with --keyspace is not allowed.");
1000
1001 return -1;
1002 }
1003
1004 if (user_options->left == true)
1005 {
1006 event_log_error (hashcat_ctx, "Combining --left with --keyspace is not allowed.");
1007
1008 return -1;
1009 }
1010 }
1011
1012 if (user_options->machine_readable == true)
1013 {
1014 if (user_options->status_json == true)
1015 {
1016 event_log_error (hashcat_ctx, "The --status-json flag can not be used with --machine-readable.");
1017
1018 return -1;
1019 }
1020 }
1021
1022 if (user_options->remove_timer_chgd == true)
1023 {
1024 if (user_options->remove == false)
1025 {
1026 event_log_error (hashcat_ctx, "The --remove-timer flag requires --remove.");
1027
1028 return -1;
1029 }
1030
1031 if (user_options->remove_timer < 1)
1032 {
1033 event_log_error (hashcat_ctx, "The --remove-timer parameter must have a value greater than or equal to 1.");
1034
1035 return -1;
1036 }
1037 }
1038
1039 if (user_options->loopback == true)
1040 {
1041 if (user_options->attack_mode == ATTACK_MODE_STRAIGHT)
1042 {
1043 if ((user_options->rp_files_cnt == 0) && (user_options->rp_gen == 0))
1044 {
1045 event_log_error (hashcat_ctx, "Parameter --loopback requires either -r/--rules-file or -g/--rules-generate.");
1046
1047 return -1;
1048 }
1049 }
1050 else
1051 {
1052 event_log_error (hashcat_ctx, "Parameter --loopback is only allowed in attack mode 0 (straight).");
1053
1054 return -1;
1055 }
1056 }
1057
1058 if (user_options->debug_mode > 0)
1059 {
1060 if (user_options->attack_mode != ATTACK_MODE_STRAIGHT)
1061 {
1062 event_log_error (hashcat_ctx, "Parameter --debug-mode option is only allowed in attack mode 0 (straight).");
1063
1064 return -1;
1065 }
1066
1067 if ((user_options->rp_files_cnt == 0) && (user_options->rp_gen == 0))
1068 {
1069 event_log_error (hashcat_ctx, "Use of --debug-mode requires -r/--rules-file or -g/--rules-generate.");
1070
1071 return -1;
1072 }
1073 }
1074
1075 if (user_options->debug_mode > 4)
1076 {
1077 event_log_error (hashcat_ctx, "Invalid --debug-mode value specified.");
1078
1079 return -1;
1080 }
1081
1082 if (user_options->debug_file != NULL)
1083 {
1084 if (user_options->debug_mode < 1)
1085 {
1086 event_log_error (hashcat_ctx, "Parameter --debug-file requires --debug-mode.");
1087
1088 return -1;
1089 }
1090 }
1091
1092 if (user_options->induction_dir != NULL)
1093 {
1094 if (user_options->attack_mode == ATTACK_MODE_BF)
1095 {
1096 event_log_error (hashcat_ctx, "Use of --induction-dir is not allowed in attack mode 3 (brute-force).");
1097
1098 return -1;
1099 }
1100
1101 if (user_options->attack_mode == ATTACK_MODE_ASSOCIATION)
1102 {
1103 event_log_error (hashcat_ctx, "Use of --induction-dir is not allowed in attack mode 9 (association).");
1104
1105 return -1;
1106 }
1107 }
1108
1109 if (user_options->spin_damp > 100)
1110 {
1111 event_log_error (hashcat_ctx, "Values of --spin-damp must be between 0 and 100 (inclusive).");
1112
1113 return -1;
1114 }
1115
1116 if (user_options->identify == true)
1117 {
1118 if (user_options->hash_mode_chgd == true)
1119 {
1120 event_log_error (hashcat_ctx, "Can't change --hash-type (-m) in identify mode.");
1121
1122 return -1;
1123 }
1124 }
1125
1126 if (user_options->benchmark == true)
1127 {
1128 // sanity checks based on automatically overwritten configuration variables by
1129 // benchmark mode section in user_options_preprocess()
1130
1131 #ifdef WITH_BRAIN
1132 if (user_options->brain_client == true)
1133 {
1134 event_log_error (hashcat_ctx, "Brain client (-z) is not allowed in benchmark mode.");
1135
1136 return -1;
1137 }
1138
1139 if (user_options->brain_server == true)
1140 {
1141 event_log_error (hashcat_ctx, "Brain server is not allowed in benchmark mode.");
1142
1143 return -1;
1144 }
1145 #endif
1146
1147 if (user_options->attack_mode_chgd == true)
1148 {
1149 event_log_error (hashcat_ctx, "Can't change --attack-mode (-a) in benchmark mode.");
1150
1151 return -1;
1152 }
1153
1154 if (user_options->bitmap_min != BITMAP_MIN)
1155 {
1156 event_log_error (hashcat_ctx, "Can't change --bitmap-min in benchmark mode.");
1157
1158 return -1;
1159 }
1160
1161 if (user_options->bitmap_max != BITMAP_MAX)
1162 {
1163 event_log_error (hashcat_ctx, "Can't change --bitmap-max in benchmark mode.");
1164
1165 return -1;
1166 }
1167
1168 if (user_options->hwmon_temp_abort != HWMON_TEMP_ABORT)
1169 {
1170 event_log_error (hashcat_ctx, "Can't change --hwmon-temp-abort in benchmark mode.");
1171
1172 return -1;
1173 }
1174
1175 if (user_options->left == true)
1176 {
1177 event_log_error (hashcat_ctx, "Can't change --left in benchmark mode.");
1178
1179 return -1;
1180 }
1181
1182 if (user_options->show == true)
1183 {
1184 event_log_error (hashcat_ctx, "Can't change --show in benchmark mode.");
1185
1186 return -1;
1187 }
1188
1189 if (user_options->speed_only == true)
1190 {
1191 event_log_error (hashcat_ctx, "Can't change --speed-only in benchmark mode.");
1192
1193 return -1;
1194 }
1195
1196 if (user_options->progress_only == true)
1197 {
1198 event_log_error (hashcat_ctx, "Can't change --progress-only in benchmark mode.");
1199
1200 return -1;
1201 }
1202
1203 if (user_options->hash_info == true)
1204 {
1205 event_log_error (hashcat_ctx, "Use of --hash-info is not allowed in benchmark mode.");
1206
1207 return -1;
1208 }
1209
1210 if (user_options->increment == true)
1211 {
1212 event_log_error (hashcat_ctx, "Can't change --increment (-i) in benchmark mode.");
1213
1214 return -1;
1215 }
1216
1217 if (user_options->restore == true)
1218 {
1219 event_log_error (hashcat_ctx, "Can't change --restore in benchmark mode.");
1220
1221 return -1;
1222 }
1223
1224 if (user_options->status == true)
1225 {
1226 event_log_error (hashcat_ctx, "Can't change --status in benchmark mode.");
1227
1228 return -1;
1229 }
1230
1231 if (user_options->spin_damp_chgd == true)
1232 {
1233 event_log_error (hashcat_ctx, "Can't change --spin-damp in benchmark mode.");
1234
1235 return -1;
1236 }
1237
1238 if ((user_options->custom_charset_1 != NULL)
1239 || (user_options->custom_charset_2 != NULL)
1240 || (user_options->custom_charset_3 != NULL)
1241 || (user_options->custom_charset_4 != NULL))
1242 {
1243 if ((user_options->attack_mode == ATTACK_MODE_STRAIGHT) || (user_options->attack_mode == ATTACK_MODE_ASSOCIATION))
1244 {
1245 event_log_error (hashcat_ctx, "Custom charsets are not supported in benchmark mode.");
1246
1247 return -1;
1248 }
1249 }
1250 }
1251
1252 if (user_options->markov_hcstat2 != NULL)
1253 {
1254 if (strlen (user_options->markov_hcstat2) == 0)
1255 {
1256 event_log_error (hashcat_ctx, "Invalid --markov-hcstat2 value - must not be empty.");
1257
1258 return -1;
1259 }
1260 }
1261
1262 if (user_options->restore_file_path != NULL)
1263 {
1264 if (strlen (user_options->restore_file_path) == 0)
1265 {
1266 event_log_error (hashcat_ctx, "Invalid --restore-file-path value - must not be empty.");
1267
1268 return -1;
1269 }
1270 }
1271
1272 if (user_options->outfile != NULL)
1273 {
1274 if (strlen (user_options->outfile) == 0)
1275 {
1276 event_log_error (hashcat_ctx, "Invalid --outfile value - must not be empty.");
1277
1278 return -1;
1279 }
1280 }
1281
1282 if (user_options->debug_file != NULL)
1283 {
1284 if (strlen (user_options->debug_file) == 0)
1285 {
1286 event_log_error (hashcat_ctx, "Invalid --debug-file value - must not be empty.");
1287
1288 return -1;
1289 }
1290 }
1291
1292 if (user_options->session != NULL)
1293 {
1294 if (strlen (user_options->session) == 0)
1295 {
1296 event_log_error (hashcat_ctx, "Invalid --session value - must not be empty.");
1297
1298 return -1;
1299 }
1300 }
1301
1302 if (user_options->cpu_affinity != NULL)
1303 {
1304 if (strlen (user_options->cpu_affinity) == 0)
1305 {
1306 event_log_error (hashcat_ctx, "Invalid --cpu-affinity value - must not be empty.");
1307
1308 return -1;
1309 }
1310 }
1311
1312 if (user_options->backend_devices != NULL)
1313 {
1314 if (strlen (user_options->backend_devices) == 0)
1315 {
1316 event_log_error (hashcat_ctx, "Invalid --backend-devices value - must not be empty.");
1317
1318 return -1;
1319 }
1320 }
1321
1322 if (user_options->opencl_device_types != NULL)
1323 {
1324 if (strlen (user_options->opencl_device_types) == 0)
1325 {
1326 event_log_error (hashcat_ctx, "Invalid --opencl-device-types value - must not be empty.");
1327
1328 return -1;
1329 }
1330 }
1331
1332 if (user_options->stdin_timeout_abort_chgd == true)
1333 {
1334 if (user_options->attack_mode != ATTACK_MODE_STRAIGHT)
1335 {
1336 event_log_error (hashcat_ctx, "Use of --stdin-timeout-abort is only allowed in attack mode 0 (straight).");
1337
1338 return -1;
1339 }
1340
1341 // --stdin-timeout-abort can only be used in stdin mode
1342
1343 if (user_options->hc_argc != 1)
1344 {
1345 event_log_error (hashcat_ctx, "Use of --stdin-timeout-abort is only allowed in stdin mode (pipe).");
1346
1347 return -1;
1348 }
1349 }
1350
1351 #ifdef WITH_BRAIN
1352 if ((user_options->brain_client == true) && (user_options->remove == true))
1353 {
1354 event_log_error (hashcat_ctx, "Using --remove is not allowed if --brain-client is used.");
1355
1356 return -1;
1357 }
1358
1359 if ((user_options->brain_client == true) && (user_options->potfile_disable == true))
1360 {
1361 event_log_error (hashcat_ctx, "Using --potfile-disable is not allowed if --brain-client is used.");
1362
1363 return -1;
1364 }
1365 #endif
1366
1367 // custom charset checks
1368
1369 if ((user_options->custom_charset_1 != NULL)
1370 || (user_options->custom_charset_2 != NULL)
1371 || (user_options->custom_charset_3 != NULL)
1372 || (user_options->custom_charset_4 != NULL))
1373 {
1374 if (user_options->attack_mode == ATTACK_MODE_STRAIGHT)
1375 {
1376 event_log_error (hashcat_ctx, "Custom charsets are not supported in attack mode 0 (straight).");
1377
1378 return -1;
1379 }
1380
1381 if (user_options->attack_mode == ATTACK_MODE_COMBI)
1382 {
1383 event_log_error (hashcat_ctx, "Custom charsets are not supported in attack mode 1 (combination).");
1384
1385 return -1;
1386 }
1387
1388 if (user_options->attack_mode == ATTACK_MODE_ASSOCIATION)
1389 {
1390 event_log_error (hashcat_ctx, "Custom charsets are not supported in attack mode 9 (association).");
1391
1392 return -1;
1393 }
1394
1395 // detect if mask was specified:
1396
1397 bool mask_is_missing = true;
1398
1399 if (user_options->keyspace == true) // special case if --keyspace was used: we need the mask but no hash file
1400 {
1401 if (user_options->hc_argc > 0) mask_is_missing = false;
1402 }
1403 else if (user_options->stdout_flag == true) // special case if --stdout was used: we need the mask but no hash file
1404 {
1405 if (user_options->hc_argc > 0) mask_is_missing = false;
1406 }
1407 else
1408 {
1409 if (user_options->hc_argc > 1) mask_is_missing = false;
1410 }
1411
1412 if (mask_is_missing == true)
1413 {
1414 event_log_error (hashcat_ctx, "If you specify a custom charset, you must also specify a mask.");
1415
1416 return -1;
1417 }
1418 }
1419
1420 // argc / argv checks
1421
1422 bool show_error = true;
1423
1424 if (user_options->version == true)
1425 {
1426 show_error = false;
1427 }
1428 else if (user_options->usage == true)
1429 {
1430 show_error = false;
1431 }
1432 #ifdef WITH_BRAIN
1433 else if (user_options->brain_server == true)
1434 {
1435 show_error = false;
1436 }
1437 #endif
1438 else if (user_options->benchmark == true)
1439 {
1440 if (user_options->hc_argc == 0)
1441 {
1442 show_error = false;
1443 }
1444 }
1445 else if (user_options->hash_info == true)
1446 {
1447 if (user_options->hc_argc == 0)
1448 {
1449 show_error = false;
1450 }
1451 }
1452 else if (user_options->backend_info == true)
1453 {
1454 if (user_options->hc_argc == 0)
1455 {
1456 show_error = false;
1457 }
1458 }
1459 else if (user_options->restore == true)
1460 {
1461 if (user_options->hc_argc == 0)
1462 {
1463 show_error = false;
1464 }
1465 }
1466 else if (user_options->keyspace == true)
1467 {
1468 if (user_options->attack_mode == ATTACK_MODE_STRAIGHT)
1469 {
1470 if (user_options->hc_argc == 1)
1471 {
1472 show_error = false;
1473 }
1474 }
1475 else if (user_options->attack_mode == ATTACK_MODE_COMBI)
1476 {
1477 if (user_options->hc_argc == 2)
1478 {
1479 show_error = false;
1480 }
1481 }
1482 else if (user_options->attack_mode == ATTACK_MODE_BF)
1483 {
1484 if (user_options->hc_argc == 1)
1485 {
1486 show_error = false;
1487 }
1488 }
1489 else if (user_options->attack_mode == ATTACK_MODE_HYBRID1)
1490 {
1491 if (user_options->hc_argc == 2)
1492 {
1493 show_error = false;
1494 }
1495 }
1496 else if (user_options->attack_mode == ATTACK_MODE_HYBRID2)
1497 {
1498 if (user_options->hc_argc == 2)
1499 {
1500 show_error = false;
1501 }
1502 }
1503 else if (user_options->attack_mode == ATTACK_MODE_ASSOCIATION)
1504 {
1505 if (user_options->hc_argc == 1)
1506 {
1507 show_error = false;
1508 }
1509 }
1510 }
1511 else if (user_options->stdout_flag == true)
1512 {
1513 if (user_options->attack_mode == ATTACK_MODE_STRAIGHT)
1514 {
1515 // all argc possible because of stdin mode
1516
1517 show_error = false;
1518 }
1519 else if (user_options->attack_mode == ATTACK_MODE_COMBI)
1520 {
1521 if (user_options->hc_argc == 2)
1522 {
1523 show_error = false;
1524 }
1525 }
1526 else if (user_options->attack_mode == ATTACK_MODE_BF)
1527 {
1528 if (user_options->hc_argc >= 1)
1529 {
1530 show_error = false;
1531 }
1532 }
1533 else if (user_options->attack_mode == ATTACK_MODE_HYBRID1)
1534 {
1535 if (user_options->hc_argc >= 1)
1536 {
1537 show_error = false;
1538 }
1539 }
1540 else if (user_options->attack_mode == ATTACK_MODE_HYBRID2)
1541 {
1542 if (user_options->hc_argc >= 1)
1543 {
1544 show_error = false;
1545 }
1546 }
1547 else if (user_options->attack_mode == ATTACK_MODE_ASSOCIATION)
1548 {
1549 if (user_options->hc_argc >= 1)
1550 {
1551 show_error = false;
1552 }
1553 }
1554 }
1555 else
1556 {
1557 if (user_options->attack_mode == ATTACK_MODE_STRAIGHT)
1558 {
1559 if (user_options->hc_argc >= 1)
1560 {
1561 show_error = false;
1562 }
1563
1564 if (user_options->hc_argc == 1)
1565 {
1566 // stdin mode
1567
1568 #ifdef WITH_BRAIN
1569 if (user_options->brain_client == true)
1570 {
1571 event_log_error (hashcat_ctx, "Use of --brain-client is not possible in stdin mode.");
1572
1573 return -1;
1574 }
1575 #endif
1576
1577 if (user_options->slow_candidates == true)
1578 {
1579 event_log_error (hashcat_ctx, "Use of --slow-candidates is not possible in stdin mode.");
1580
1581 return -1;
1582 }
1583 }
1584 }
1585 else if (user_options->attack_mode == ATTACK_MODE_COMBI)
1586 {
1587 if (user_options->hc_argc == 3)
1588 {
1589 show_error = false;
1590 }
1591 }
1592 else if (user_options->attack_mode == ATTACK_MODE_BF)
1593 {
1594 if (user_options->hc_argc >= 1)
1595 {
1596 show_error = false;
1597 }
1598 }
1599 else if (user_options->attack_mode == ATTACK_MODE_HYBRID1)
1600 {
1601 if (user_options->hc_argc >= 2)
1602 {
1603 show_error = false;
1604 }
1605 }
1606 else if (user_options->attack_mode == ATTACK_MODE_HYBRID2)
1607 {
1608 if (user_options->hc_argc >= 2)
1609 {
1610 show_error = false;
1611 }
1612 }
1613 else if (user_options->attack_mode == ATTACK_MODE_ASSOCIATION)
1614 {
1615 if (user_options->hc_argc >= 2)
1616 {
1617 show_error = false;
1618 }
1619 }
1620 }
1621
1622 if (show_error == true)
1623 {
1624 usage_mini_print (user_options->hc_bin);
1625
1626 return -1;
1627 }
1628
1629 return 0;
1630 }
1631
user_options_session_auto(hashcat_ctx_t * hashcat_ctx)1632 void user_options_session_auto (hashcat_ctx_t *hashcat_ctx)
1633 {
1634 user_options_t *user_options = hashcat_ctx->user_options;
1635
1636 if (strcmp (user_options->session, PROGNAME) == 0)
1637 {
1638 if (user_options->benchmark == true)
1639 {
1640 user_options->session = "benchmark";
1641 }
1642
1643 if (user_options->hash_info == true)
1644 {
1645 user_options->session = "hash_info";
1646 }
1647
1648 if (user_options->usage == true)
1649 {
1650 user_options->session = "usage";
1651 }
1652
1653 if (user_options->speed_only == true)
1654 {
1655 user_options->session = "speed_only";
1656 }
1657
1658 if (user_options->progress_only == true)
1659 {
1660 user_options->session = "progress_only";
1661 }
1662
1663 if (user_options->keyspace == true)
1664 {
1665 user_options->session = "keyspace";
1666 }
1667
1668 if (user_options->stdout_flag == true)
1669 {
1670 user_options->session = "stdout";
1671 }
1672
1673 if (user_options->backend_info == true)
1674 {
1675 user_options->session = "backend_info";
1676 }
1677
1678 if (user_options->show == true)
1679 {
1680 user_options->session = "show";
1681 }
1682
1683 if (user_options->left == true)
1684 {
1685 user_options->session = "left";
1686 }
1687
1688 if (user_options->identify == true)
1689 {
1690 user_options->session = "identify";
1691 }
1692 }
1693 }
1694
user_options_preprocess(hashcat_ctx_t * hashcat_ctx)1695 void user_options_preprocess (hashcat_ctx_t *hashcat_ctx)
1696 {
1697 user_options_t *user_options = hashcat_ctx->user_options;
1698
1699 // some options can influence or overwrite other options
1700
1701 #ifdef WITH_BRAIN
1702 if (user_options->brain_client == true)
1703 {
1704 user_options->slow_candidates = true;
1705 }
1706 #endif
1707
1708 if (user_options->stdout_flag)
1709 {
1710 user_options->hwmon_disable = true;
1711 user_options->left = false;
1712 user_options->logfile_disable = true;
1713 user_options->spin_damp = 0;
1714 user_options->outfile_check_timer = 0;
1715 user_options->potfile_disable = true;
1716 user_options->restore_disable = true;
1717 user_options->restore = false;
1718 user_options->restore_timer = 0;
1719 user_options->show = false;
1720 user_options->status = false;
1721 user_options->status_timer = 0;
1722 user_options->bitmap_min = 1;
1723 user_options->bitmap_max = 1;
1724 }
1725
1726 if (user_options->hash_info == true
1727 || user_options->backend_info == true
1728 || user_options->keyspace == true
1729 || user_options->speed_only == true
1730 || user_options->progress_only == true
1731 || user_options->identify == true
1732 || user_options->usage == true)
1733 {
1734 user_options->hwmon_disable = true;
1735 user_options->left = false;
1736 user_options->logfile_disable = true;
1737 user_options->spin_damp = 0;
1738 user_options->outfile_check_timer = 0;
1739 user_options->potfile_disable = true;
1740 user_options->restore_disable = true;
1741 user_options->restore = false;
1742 user_options->restore_timer = 0;
1743 user_options->show = false;
1744 user_options->status = false;
1745 user_options->status_timer = 0;
1746 user_options->bitmap_min = 1;
1747 user_options->bitmap_max = 1;
1748 #ifdef WITH_BRAIN
1749 user_options->brain_client = false;
1750 #endif
1751 }
1752
1753 if (user_options->benchmark == true)
1754 {
1755 user_options->attack_mode = ATTACK_MODE_BF;
1756 user_options->hwmon_temp_abort = 0;
1757 user_options->increment = false;
1758 user_options->left = false;
1759 user_options->logfile_disable = true;
1760 user_options->spin_damp = 0;
1761 user_options->potfile_disable = true;
1762 user_options->progress_only = false;
1763 user_options->restore_disable = true;
1764 user_options->restore = false;
1765 user_options->restore_timer = 0;
1766 user_options->show = false;
1767 user_options->speed_only = true;
1768 user_options->status = false;
1769 user_options->status_timer = 0;
1770 user_options->bitmap_min = 1;
1771 user_options->bitmap_max = 1;
1772 #ifdef WITH_BRAIN
1773 user_options->brain_client = false;
1774 #endif
1775
1776 if (user_options->workload_profile_chgd == false)
1777 {
1778 user_options->optimized_kernel_enable = true;
1779 user_options->workload_profile = 3;
1780 }
1781 }
1782
1783 if (user_options->hash_info == true)
1784 {
1785 user_options->quiet = true;
1786 }
1787
1788 if (user_options->usage == true)
1789 {
1790 user_options->quiet = true;
1791 }
1792
1793 if (user_options->progress_only == true)
1794 {
1795 user_options->speed_only = true;
1796 }
1797
1798 if (user_options->keyspace == true)
1799 {
1800 user_options->quiet = true;
1801 }
1802
1803 if (user_options->slow_candidates == true)
1804 {
1805 user_options->backend_vector_width = 1;
1806 }
1807
1808 if (user_options->stdout_flag == true)
1809 {
1810 user_options->force = true;
1811 user_options->hash_mode = 2000;
1812 user_options->kernel_accel = 1024;
1813 user_options->backend_vector_width = 1;
1814 user_options->outfile_format = OUTFILE_FMT_PLAIN;
1815 user_options->quiet = true;
1816
1817 if (user_options->attack_mode == ATTACK_MODE_STRAIGHT)
1818 {
1819 user_options->kernel_loops = KERNEL_RULES;
1820 }
1821 else if (user_options->attack_mode == ATTACK_MODE_COMBI)
1822 {
1823 user_options->kernel_loops = KERNEL_COMBS;
1824 }
1825 else if (user_options->attack_mode == ATTACK_MODE_BF)
1826 {
1827 user_options->kernel_loops = KERNEL_BFS;
1828 }
1829 else if (user_options->attack_mode == ATTACK_MODE_HYBRID1)
1830 {
1831 user_options->kernel_loops = KERNEL_COMBS;
1832 }
1833 else if (user_options->attack_mode == ATTACK_MODE_HYBRID2)
1834 {
1835 user_options->kernel_loops = KERNEL_COMBS;
1836 }
1837 else if (user_options->attack_mode == ATTACK_MODE_ASSOCIATION)
1838 {
1839 user_options->kernel_loops = KERNEL_RULES;
1840 }
1841 }
1842
1843 if (user_options->backend_info == true)
1844 {
1845 user_options->backend_devices = NULL;
1846 user_options->opencl_device_types = hcstrdup ("1,2,3");
1847 user_options->quiet = true;
1848 }
1849
1850 if (user_options->left == true)
1851 {
1852 user_options->outfile_format = OUTFILE_FMT_HASH;
1853 }
1854
1855 if (user_options->show == true || user_options->left == true)
1856 {
1857 user_options->attack_mode = ATTACK_MODE_NONE;
1858 user_options->quiet = true;
1859 }
1860
1861 // this allows the user to use --show and --left while cracking (i.e. while another instance of hashcat is running)
1862 if (user_options->show == true || user_options->left == true)
1863 {
1864 user_options->restore_disable = true;
1865
1866 user_options->restore = false;
1867 }
1868
1869 if (user_options->skip != 0 && user_options->limit != 0)
1870 {
1871 user_options->limit += user_options->skip;
1872 }
1873
1874 if (user_options->markov_threshold == 0)
1875 {
1876 user_options->markov_threshold = 0x100;
1877 }
1878
1879 if (user_options->segment_size_chgd == true)
1880 {
1881 user_options->segment_size *= (1024 * 1024);
1882 }
1883
1884 #if !defined (WITH_HWMON)
1885 user_options->hwmon_disable = true;
1886 #endif // WITH_HWMON
1887
1888 if (user_options->hwmon_disable == true)
1889 {
1890 user_options->hwmon_temp_abort = 0;
1891 }
1892
1893 // default mask
1894
1895 if (user_options->attack_mode == ATTACK_MODE_BF)
1896 {
1897 if (user_options->hash_info == true)
1898 {
1899
1900 }
1901 else if (user_options->backend_info == true)
1902 {
1903
1904 }
1905 else if (user_options->speed_only == true)
1906 {
1907
1908 }
1909 else if (user_options->keyspace == true)
1910 {
1911 if (user_options->hc_argc == 0)
1912 {
1913 user_options->custom_charset_1 = DEF_MASK_CS_1;
1914 user_options->custom_charset_2 = DEF_MASK_CS_2;
1915 user_options->custom_charset_3 = DEF_MASK_CS_3;
1916
1917 user_options->increment = true;
1918 }
1919 }
1920 else if (user_options->stdout_flag == true)
1921 {
1922 if (user_options->hc_argc == 0)
1923 {
1924 user_options->custom_charset_1 = DEF_MASK_CS_1;
1925 user_options->custom_charset_2 = DEF_MASK_CS_2;
1926 user_options->custom_charset_3 = DEF_MASK_CS_3;
1927
1928 user_options->increment = true;
1929 }
1930 }
1931 else
1932 {
1933 if (user_options->hc_argc == 1)
1934 {
1935 user_options->custom_charset_1 = DEF_MASK_CS_1;
1936 user_options->custom_charset_2 = DEF_MASK_CS_2;
1937 user_options->custom_charset_3 = DEF_MASK_CS_3;
1938
1939 user_options->increment = true;
1940 }
1941 }
1942 }
1943
1944 // association limitations
1945
1946 if (user_options->attack_mode == ATTACK_MODE_ASSOCIATION)
1947 {
1948 user_options->potfile_disable = true;
1949 }
1950
1951 if (user_options->stdout_flag == false && user_options->benchmark == false && user_options->keyspace == false)
1952 {
1953 if (user_options->hash_mode == 0 && user_options->hash_mode_chgd == false)
1954 {
1955 user_options->autodetect = true;
1956 }
1957 }
1958 }
1959
user_options_postprocess(hashcat_ctx_t * hashcat_ctx)1960 void user_options_postprocess (hashcat_ctx_t *hashcat_ctx)
1961 {
1962 user_options_t *user_options = hashcat_ctx->user_options;
1963 user_options_extra_t *user_options_extra = hashcat_ctx->user_options_extra;
1964
1965 // automatic status
1966
1967 if (user_options_extra->wordlist_mode == WL_MODE_STDIN)
1968 {
1969 user_options->status = true;
1970 }
1971 }
1972
user_options_info(hashcat_ctx_t * hashcat_ctx)1973 void user_options_info (hashcat_ctx_t *hashcat_ctx)
1974 {
1975 const user_options_t *user_options = hashcat_ctx->user_options;
1976
1977 if (user_options->quiet == true) return;
1978
1979 if (user_options->benchmark == false) return;
1980
1981 if (user_options->machine_readable == false)
1982 {
1983 event_log_info (hashcat_ctx, "Benchmark relevant options:");
1984 event_log_info (hashcat_ctx, "===========================");
1985
1986 if (user_options->benchmark_all == true)
1987 {
1988 event_log_info (hashcat_ctx, "* --benchmark-all");
1989 }
1990
1991 if (user_options->force == true)
1992 {
1993 event_log_info (hashcat_ctx, "* --force");
1994 }
1995
1996 if (user_options->backend_devices)
1997 {
1998 event_log_info (hashcat_ctx, "* --backend-devices=%s", user_options->backend_devices);
1999 }
2000
2001 if (user_options->opencl_device_types)
2002 {
2003 event_log_info (hashcat_ctx, "* --opencl-device-types=%s", user_options->opencl_device_types);
2004 }
2005
2006 if (user_options->optimized_kernel_enable == true)
2007 {
2008 event_log_info (hashcat_ctx, "* --optimized-kernel-enable");
2009 }
2010
2011 if (user_options->multiply_accel_disable == true)
2012 {
2013 event_log_info (hashcat_ctx, "* --multiply-accel-disable");
2014 }
2015
2016 if (user_options->backend_vector_width_chgd == true)
2017 {
2018 event_log_info (hashcat_ctx, "* --backend-vector-width=%u", user_options->backend_vector_width);
2019 }
2020
2021 if (user_options->kernel_accel_chgd == true)
2022 {
2023 event_log_info (hashcat_ctx, "* --kernel-accel=%u", user_options->kernel_accel);
2024 }
2025 else if (user_options->kernel_loops_chgd == true)
2026 {
2027 event_log_info (hashcat_ctx, "* --kernel-loops=%u", user_options->kernel_loops);
2028 }
2029 else if (user_options->kernel_threads_chgd == true)
2030 {
2031 event_log_info (hashcat_ctx, "* --kernel-threads=%u", user_options->kernel_threads);
2032 }
2033 else
2034 {
2035 if (user_options->workload_profile_chgd == true)
2036 {
2037 event_log_info (hashcat_ctx, "* --workload-profile=%u", user_options->workload_profile);
2038 }
2039 }
2040
2041 event_log_info (hashcat_ctx, NULL);
2042 }
2043 else
2044 {
2045 if (user_options->benchmark_all == true)
2046 {
2047 event_log_info (hashcat_ctx, "# option: --benchmark-all");
2048 }
2049
2050 if (user_options->force == true)
2051 {
2052 event_log_info (hashcat_ctx, "# option: --force");
2053 }
2054
2055 if (user_options->backend_devices)
2056 {
2057 event_log_info (hashcat_ctx, "# option: --backend-devices=%s", user_options->backend_devices);
2058 }
2059
2060 if (user_options->opencl_device_types)
2061 {
2062 event_log_info (hashcat_ctx, "# option: --opencl-device-types=%s", user_options->opencl_device_types);
2063 }
2064
2065 if (user_options->optimized_kernel_enable == true)
2066 {
2067 event_log_info (hashcat_ctx, "# option: --optimized-kernel-enable");
2068 }
2069
2070 if (user_options->multiply_accel_disable == true)
2071 {
2072 event_log_info (hashcat_ctx, "# option: --multiply-accel-disable");
2073 }
2074
2075 if (user_options->backend_vector_width_chgd == true)
2076 {
2077 event_log_info (hashcat_ctx, "# option: --backend-vector-width=%u", user_options->backend_vector_width);
2078 }
2079
2080 if (user_options->kernel_accel_chgd == true)
2081 {
2082 event_log_info (hashcat_ctx, "# option: --kernel-accel=%u", user_options->kernel_accel);
2083 }
2084 else if (user_options->kernel_loops_chgd == true)
2085 {
2086 event_log_info (hashcat_ctx, "# option: --kernel-loops=%u", user_options->kernel_loops);
2087 }
2088 else if (user_options->kernel_threads_chgd == true)
2089 {
2090 event_log_info (hashcat_ctx, "# option: --kernel-threads=%u", user_options->kernel_threads);
2091 }
2092 else
2093 {
2094 if (user_options->workload_profile_chgd == true)
2095 {
2096 event_log_info (hashcat_ctx, "# option: --workload-profile=%u", user_options->workload_profile);
2097 }
2098 }
2099 }
2100 }
2101
user_options_extra_init(hashcat_ctx_t * hashcat_ctx)2102 void user_options_extra_init (hashcat_ctx_t *hashcat_ctx)
2103 {
2104 user_options_t *user_options = hashcat_ctx->user_options;
2105 user_options_extra_t *user_options_extra = hashcat_ctx->user_options_extra;
2106
2107 // separator
2108
2109 if (user_options->separator)
2110 {
2111 user_options_extra->separator = user_options->separator[0];
2112 }
2113
2114 // attack-kern
2115
2116 user_options_extra->attack_kern = ATTACK_KERN_NONE;
2117
2118 switch (user_options->attack_mode)
2119 {
2120 case ATTACK_MODE_STRAIGHT: user_options_extra->attack_kern = ATTACK_KERN_STRAIGHT; break;
2121 case ATTACK_MODE_COMBI: user_options_extra->attack_kern = ATTACK_KERN_COMBI; break;
2122 case ATTACK_MODE_BF: user_options_extra->attack_kern = ATTACK_KERN_BF; break;
2123 case ATTACK_MODE_HYBRID1: user_options_extra->attack_kern = ATTACK_KERN_COMBI; break;
2124 case ATTACK_MODE_HYBRID2: user_options_extra->attack_kern = ATTACK_KERN_COMBI; break;
2125 case ATTACK_MODE_ASSOCIATION: user_options_extra->attack_kern = ATTACK_KERN_STRAIGHT; break;
2126 }
2127
2128 // rules
2129
2130 user_options_extra->rule_len_l = (int) strlen (user_options->rule_buf_l);
2131 user_options_extra->rule_len_r = (int) strlen (user_options->rule_buf_r);
2132
2133 // hc_hash and hc_work*
2134
2135 user_options_extra->hc_hash = NULL;
2136 user_options_extra->hc_workv = NULL;
2137 user_options_extra->hc_workc = 0;
2138
2139 if (user_options->benchmark == true)
2140 {
2141
2142 }
2143 else if (user_options->hash_info == true)
2144 {
2145
2146 }
2147 else if (user_options->backend_info == true)
2148 {
2149
2150 }
2151 else if (user_options->keyspace == true)
2152 {
2153 user_options_extra->hc_workc = user_options->hc_argc;
2154 user_options_extra->hc_workv = user_options->hc_argv;
2155 }
2156 else if (user_options->stdout_flag == true)
2157 {
2158 user_options_extra->hc_workc = user_options->hc_argc;
2159 user_options_extra->hc_workv = user_options->hc_argv;
2160 }
2161 else
2162 {
2163 user_options_extra->hc_hash = user_options->hc_argv[0];
2164 user_options_extra->hc_workc = user_options->hc_argc - 1;
2165 user_options_extra->hc_workv = user_options->hc_argv + 1;
2166 }
2167
2168 // wordlist_mode
2169
2170 user_options_extra->wordlist_mode = WL_MODE_NONE;
2171
2172 if (user_options_extra->attack_kern == ATTACK_KERN_STRAIGHT)
2173 {
2174 user_options_extra->wordlist_mode = (user_options_extra->hc_workc >= 1) ? WL_MODE_FILE : WL_MODE_STDIN;
2175 }
2176 else if (user_options_extra->attack_kern == ATTACK_KERN_COMBI)
2177 {
2178 user_options_extra->wordlist_mode = WL_MODE_FILE;
2179 }
2180 else if (user_options_extra->attack_kern == ATTACK_KERN_BF)
2181 {
2182 user_options_extra->wordlist_mode = WL_MODE_MASK;
2183 }
2184 }
2185
user_options_extra_destroy(hashcat_ctx_t * hashcat_ctx)2186 void user_options_extra_destroy (hashcat_ctx_t *hashcat_ctx)
2187 {
2188 user_options_extra_t *user_options_extra = hashcat_ctx->user_options_extra;
2189
2190 memset (user_options_extra, 0, sizeof (user_options_extra_t));
2191 }
2192
user_options_extra_amplifier(hashcat_ctx_t * hashcat_ctx)2193 u64 user_options_extra_amplifier (hashcat_ctx_t *hashcat_ctx)
2194 {
2195 const combinator_ctx_t *combinator_ctx = hashcat_ctx->combinator_ctx;
2196 const mask_ctx_t *mask_ctx = hashcat_ctx->mask_ctx;
2197 const straight_ctx_t *straight_ctx = hashcat_ctx->straight_ctx;
2198 const user_options_t *user_options = hashcat_ctx->user_options;
2199 const user_options_extra_t *user_options_extra = hashcat_ctx->user_options_extra;
2200
2201 if (user_options->slow_candidates == true)
2202 {
2203 return 1;
2204 }
2205
2206 if (user_options_extra->attack_kern == ATTACK_KERN_STRAIGHT)
2207 {
2208 if (straight_ctx->kernel_rules_cnt)
2209 {
2210 return straight_ctx->kernel_rules_cnt;
2211 }
2212 }
2213 else if (user_options_extra->attack_kern == ATTACK_KERN_COMBI)
2214 {
2215 if (combinator_ctx->combs_cnt)
2216 {
2217 return combinator_ctx->combs_cnt;
2218 }
2219 }
2220 else if (user_options_extra->attack_kern == ATTACK_KERN_BF)
2221 {
2222 if (mask_ctx->bfs_cnt)
2223 {
2224 return mask_ctx->bfs_cnt;
2225 }
2226 }
2227
2228 return 1;
2229 }
2230
user_options_check_files(hashcat_ctx_t * hashcat_ctx)2231 int user_options_check_files (hashcat_ctx_t *hashcat_ctx)
2232 {
2233 dictstat_ctx_t *dictstat_ctx = hashcat_ctx->dictstat_ctx;
2234 folder_config_t *folder_config = hashcat_ctx->folder_config;
2235 logfile_ctx_t *logfile_ctx = hashcat_ctx->logfile_ctx;
2236 outcheck_ctx_t *outcheck_ctx = hashcat_ctx->outcheck_ctx;
2237 outfile_ctx_t *outfile_ctx = hashcat_ctx->outfile_ctx;
2238 pidfile_ctx_t *pidfile_ctx = hashcat_ctx->pidfile_ctx;
2239 potfile_ctx_t *potfile_ctx = hashcat_ctx->potfile_ctx;
2240 user_options_extra_t *user_options_extra = hashcat_ctx->user_options_extra;
2241 user_options_t *user_options = hashcat_ctx->user_options;
2242
2243 // brain
2244
2245 #ifdef WITH_BRAIN
2246 if (user_options->brain_host)
2247 {
2248 struct addrinfo hints;
2249
2250 memset (&hints, 0, sizeof (hints));
2251
2252 hints.ai_family = AF_INET;
2253 hints.ai_socktype = SOCK_STREAM;
2254
2255 struct addrinfo *address_info = NULL;
2256
2257 const int rc_getaddrinfo = getaddrinfo (user_options->brain_host, NULL, &hints, &address_info);
2258
2259 if (rc_getaddrinfo != 0)
2260 {
2261 fprintf (stderr, "%s: %s\n", user_options->brain_host, gai_strerror (rc_getaddrinfo));
2262
2263 return -1;
2264 }
2265
2266 freeaddrinfo (address_info);
2267 }
2268 #endif
2269
2270 // common folders
2271
2272 #if defined (_WIN)
2273 if (hc_path_read (".") == false)
2274 {
2275 event_log_error (hashcat_ctx, "%s: %s", ".", strerror (errno));
2276
2277 return -1;
2278 }
2279 #else
2280 if (hc_path_read (folder_config->cwd) == false)
2281 {
2282 event_log_error (hashcat_ctx, "%s: %s", folder_config->cwd, strerror (errno));
2283
2284 return -1;
2285 }
2286 #endif
2287
2288 if (hc_path_read (folder_config->install_dir) == false)
2289 {
2290 event_log_error (hashcat_ctx, "%s: %s", folder_config->install_dir, strerror (errno));
2291
2292 return -1;
2293 }
2294
2295 if (hc_path_read (folder_config->profile_dir) == false)
2296 {
2297 event_log_error (hashcat_ctx, "%s: %s", folder_config->profile_dir, strerror (errno));
2298
2299 return -1;
2300 }
2301
2302 if (hc_path_write (folder_config->session_dir) == false)
2303 {
2304 event_log_error (hashcat_ctx, "%s: %s", folder_config->session_dir, strerror (errno));
2305
2306 return -1;
2307 }
2308
2309 if (hc_path_read (folder_config->shared_dir) == false)
2310 {
2311 event_log_error (hashcat_ctx, "%s: %s", folder_config->shared_dir, strerror (errno));
2312
2313 return -1;
2314 }
2315
2316 if (hc_path_read (folder_config->cpath_real) == false)
2317 {
2318 event_log_error (hashcat_ctx, "%s: %s", folder_config->cpath_real, strerror (errno));
2319
2320 return -1;
2321 }
2322
2323 // hashfile - can be NULL
2324
2325 if (user_options_extra->hc_hash != NULL)
2326 {
2327 if (hc_path_exist (user_options_extra->hc_hash) == true)
2328 {
2329 if (hc_path_is_directory (user_options_extra->hc_hash) == true)
2330 {
2331 event_log_error (hashcat_ctx, "%s: A directory cannot be used as a hashfile argument.", user_options_extra->hc_hash);
2332
2333 return -1;
2334 }
2335
2336 if (hc_path_read (user_options_extra->hc_hash) == false)
2337 {
2338 event_log_error (hashcat_ctx, "%s: %s", user_options_extra->hc_hash, strerror (errno));
2339
2340 return -1;
2341 }
2342
2343 if (hc_path_has_bom (user_options_extra->hc_hash) == true)
2344 {
2345 event_log_warning (hashcat_ctx, "%s: Byte Order Mark (BOM) was detected", user_options_extra->hc_hash);
2346
2347 //return -1;
2348 }
2349 }
2350 }
2351
2352 // arguments - checks must depend on attack_mode
2353
2354 if (user_options->attack_mode == ATTACK_MODE_STRAIGHT)
2355 {
2356 for (int i = 0; i < user_options_extra->hc_workc; i++)
2357 {
2358 char *wlfile = user_options_extra->hc_workv[i];
2359
2360 if (hc_path_exist (wlfile) == false)
2361 {
2362 event_log_error (hashcat_ctx, "%s: %s", wlfile, strerror (errno));
2363
2364 return -1;
2365 }
2366 }
2367
2368 for (int i = 0; i < (int) user_options->rp_files_cnt; i++)
2369 {
2370 char *rp_file = user_options->rp_files[i];
2371
2372 if (hc_path_exist (rp_file) == false)
2373 {
2374 event_log_error (hashcat_ctx, "%s: %s", rp_file, strerror (errno));
2375
2376 return -1;
2377 }
2378
2379 if (hc_path_is_directory (rp_file) == true)
2380 {
2381 event_log_error (hashcat_ctx, "%s: A directory cannot be used as a rulefile argument.", rp_file);
2382
2383 return -1;
2384 }
2385
2386 if (hc_path_read (rp_file) == false)
2387 {
2388 event_log_error (hashcat_ctx, "%s: %s", rp_file, strerror (errno));
2389
2390 return -1;
2391 }
2392
2393 if (hc_path_has_bom (rp_file) == true)
2394 {
2395 event_log_warning (hashcat_ctx, "%s: Byte Order Mark (BOM) was detected", rp_file);
2396
2397 //return -1;
2398 }
2399 }
2400 }
2401 else if (user_options->attack_mode == ATTACK_MODE_COMBI)
2402 {
2403 // mode easy mode here because both files must exist and readable
2404
2405 if (user_options_extra->hc_workc == 2)
2406 {
2407 char *dictfile1 = user_options_extra->hc_workv[0];
2408 char *dictfile2 = user_options_extra->hc_workv[1];
2409
2410 if (hc_path_exist (dictfile1) == false)
2411 {
2412 event_log_error (hashcat_ctx, "%s: %s", dictfile1, strerror (errno));
2413
2414 return -1;
2415 }
2416
2417 if (hc_path_is_directory (dictfile1) == true)
2418 {
2419 event_log_error (hashcat_ctx, "%s: A directory cannot be used as a wordlist argument.", dictfile1);
2420
2421 return -1;
2422 }
2423
2424 if (hc_path_read (dictfile1) == false)
2425 {
2426 event_log_error (hashcat_ctx, "%s: %s", dictfile1, strerror (errno));
2427
2428 return -1;
2429 }
2430
2431 if (hc_path_has_bom (dictfile1) == true)
2432 {
2433 event_log_warning (hashcat_ctx, "%s: Byte Order Mark (BOM) was detected", dictfile1);
2434
2435 //return -1;
2436 }
2437
2438 if (hc_path_exist (dictfile2) == false)
2439 {
2440 event_log_error (hashcat_ctx, "%s: %s", dictfile2, strerror (errno));
2441
2442 return -1;
2443 }
2444
2445 if (hc_path_is_directory (dictfile2) == true)
2446 {
2447 event_log_error (hashcat_ctx, "%s: A directory cannot be used as a wordlist argument.", dictfile2);
2448
2449 return -1;
2450 }
2451
2452 if (hc_path_read (dictfile2) == false)
2453 {
2454 event_log_error (hashcat_ctx, "%s: %s", dictfile2, strerror (errno));
2455
2456 return -1;
2457 }
2458
2459 if (hc_path_has_bom (dictfile2) == true)
2460 {
2461 event_log_warning (hashcat_ctx, "%s: Byte Order Mark (BOM) was detected", dictfile2);
2462
2463 //return -1;
2464 }
2465 }
2466 }
2467 else if (user_options->attack_mode == ATTACK_MODE_BF)
2468 {
2469 // if the file exist it's a maskfile and then it must be readable
2470
2471 if (user_options_extra->hc_workc == 1)
2472 {
2473 char *maskfile = user_options_extra->hc_workv[0];
2474
2475 if (hc_path_exist (maskfile) == true)
2476 {
2477 if (hc_path_is_directory (maskfile) == true)
2478 {
2479 event_log_error (hashcat_ctx, "%s: A directory cannot be used as a maskfile argument.", maskfile);
2480
2481 return -1;
2482 }
2483
2484 if (hc_path_read (maskfile) == false)
2485 {
2486 event_log_error (hashcat_ctx, "%s: %s", maskfile, strerror (errno));
2487
2488 return -1;
2489 }
2490
2491 if (hc_path_has_bom (maskfile) == true)
2492 {
2493 event_log_warning (hashcat_ctx, "%s: Byte Order Mark (BOM) was detected", maskfile);
2494
2495 //return -1;
2496 }
2497 }
2498 }
2499 }
2500 else if (user_options->attack_mode == ATTACK_MODE_HYBRID1)
2501 {
2502 if (user_options_extra->hc_workc == 2)
2503 {
2504 char *wlfile = user_options_extra->hc_workv[0];
2505
2506 char *maskfile = user_options_extra->hc_workv[1];
2507
2508 // for wordlist: can be folder
2509
2510 if (hc_path_exist (wlfile) == false)
2511 {
2512 event_log_error (hashcat_ctx, "%s: %s", wlfile, strerror (errno));
2513
2514 return -1;
2515 }
2516
2517 // for mask: if the file exist it's a maskfile and then it must be readable
2518
2519 if (hc_path_exist (maskfile) == true)
2520 {
2521 if (hc_path_is_directory (maskfile) == true)
2522 {
2523 event_log_error (hashcat_ctx, "%s: A directory cannot be used as a maskfile argument.", maskfile);
2524
2525 return -1;
2526 }
2527
2528 if (hc_path_read (maskfile) == false)
2529 {
2530 event_log_error (hashcat_ctx, "%s: %s", maskfile, strerror (errno));
2531
2532 return -1;
2533 }
2534
2535 if (hc_path_has_bom (maskfile) == true)
2536 {
2537 event_log_warning (hashcat_ctx, "%s: Byte Order Mark (BOM) was detected", maskfile);
2538
2539 //return -1;
2540 }
2541 }
2542 }
2543 }
2544 else if (user_options->attack_mode == ATTACK_MODE_HYBRID2)
2545 {
2546 if (user_options_extra->hc_workc == 2)
2547 {
2548 char *wlfile = user_options_extra->hc_workv[1];
2549
2550 char *maskfile = user_options_extra->hc_workv[0];
2551
2552 // for wordlist: can be folder
2553
2554 if (hc_path_exist (wlfile) == false)
2555 {
2556 event_log_error (hashcat_ctx, "%s: %s", wlfile, strerror (errno));
2557
2558 return -1;
2559 }
2560
2561 // for mask: if the file exist it's a maskfile and then it must be readable
2562
2563 if (hc_path_exist (maskfile) == true)
2564 {
2565 if (hc_path_is_directory (maskfile) == true)
2566 {
2567 event_log_error (hashcat_ctx, "%s: A directory cannot be used as a maskfile argument.", maskfile);
2568
2569 return -1;
2570 }
2571
2572 if (hc_path_read (maskfile) == false)
2573 {
2574 event_log_error (hashcat_ctx, "%s: %s", maskfile, strerror (errno));
2575
2576 return -1;
2577 }
2578
2579 if (hc_path_has_bom (maskfile) == true)
2580 {
2581 event_log_warning (hashcat_ctx, "%s: Byte Order Mark (BOM) was detected", maskfile);
2582
2583 //return -1;
2584 }
2585 }
2586 }
2587 }
2588 else if (user_options->attack_mode == ATTACK_MODE_ASSOCIATION)
2589 {
2590 for (int i = 0; i < user_options_extra->hc_workc; i++)
2591 {
2592 char *wlfile = user_options_extra->hc_workv[i];
2593
2594 if (hc_path_exist (wlfile) == false)
2595 {
2596 event_log_error (hashcat_ctx, "%s: %s", wlfile, strerror (errno));
2597
2598 return -1;
2599 }
2600 }
2601
2602 for (int i = 0; i < (int) user_options->rp_files_cnt; i++)
2603 {
2604 char *rp_file = user_options->rp_files[i];
2605
2606 if (hc_path_exist (rp_file) == false)
2607 {
2608 event_log_error (hashcat_ctx, "%s: %s", rp_file, strerror (errno));
2609
2610 return -1;
2611 }
2612
2613 if (hc_path_is_directory (rp_file) == true)
2614 {
2615 event_log_error (hashcat_ctx, "%s: A directory cannot be used as a rulefile argument.", rp_file);
2616
2617 return -1;
2618 }
2619
2620 if (hc_path_read (rp_file) == false)
2621 {
2622 event_log_error (hashcat_ctx, "%s: %s", rp_file, strerror (errno));
2623
2624 return -1;
2625 }
2626
2627 if (hc_path_has_bom (rp_file) == true)
2628 {
2629 event_log_warning (hashcat_ctx, "%s: Byte Order Mark (BOM) was detected", rp_file);
2630
2631 //return -1;
2632 }
2633 }
2634 }
2635
2636 // logfile
2637
2638 if (logfile_ctx->enabled == true)
2639 {
2640 if (hc_path_exist (logfile_ctx->logfile) == true)
2641 {
2642 if (hc_path_is_directory (logfile_ctx->logfile) == true)
2643 {
2644 event_log_error (hashcat_ctx, "%s: A directory cannot be used as a logfile argument.", logfile_ctx->logfile);
2645
2646 return -1;
2647 }
2648
2649 if (hc_path_write (logfile_ctx->logfile) == false)
2650 {
2651 event_log_error (hashcat_ctx, "%s: %s", logfile_ctx->logfile, strerror (errno));
2652
2653 return -1;
2654 }
2655 }
2656 else
2657 {
2658 if (hc_path_create (logfile_ctx->logfile) == false)
2659 {
2660 event_log_error (hashcat_ctx, "%s: %s", logfile_ctx->logfile, strerror (errno));
2661
2662 return -1;
2663 }
2664 }
2665 }
2666
2667 // outfile_check
2668
2669 if (outcheck_ctx->enabled == true)
2670 {
2671 if (hc_path_exist (outcheck_ctx->root_directory) == true)
2672 {
2673 if (hc_path_is_directory (outcheck_ctx->root_directory) == false)
2674 {
2675 event_log_error (hashcat_ctx, "Directory specified in outfile-check '%s' is not a directory.", outcheck_ctx->root_directory);
2676
2677 return -1;
2678 }
2679 }
2680 }
2681
2682 // outfile - can be NULL
2683
2684 if (outfile_ctx->filename != NULL)
2685 {
2686 if (hc_path_exist (outfile_ctx->filename) == true)
2687 {
2688 if (hc_path_is_directory (outfile_ctx->filename) == true)
2689 {
2690 event_log_error (hashcat_ctx, "%s: A directory cannot be used as an outfile.", outfile_ctx->filename);
2691
2692 return -1;
2693 }
2694
2695 if (hc_path_write (outfile_ctx->filename) == false)
2696 {
2697 event_log_error (hashcat_ctx, "%s: %s", outfile_ctx->filename, strerror (errno));
2698
2699 return -1;
2700 }
2701 }
2702 else
2703 {
2704 if (hc_path_create (outfile_ctx->filename) == false)
2705 {
2706 event_log_error (hashcat_ctx, "%s: %s", outfile_ctx->filename, strerror (errno));
2707
2708 return -1;
2709 }
2710 }
2711 }
2712
2713 // check for outfile vs. hashfile
2714
2715 if (hc_same_files (outfile_ctx->filename, user_options_extra->hc_hash) == true)
2716 {
2717 event_log_error (hashcat_ctx, "Outfile and hashfile cannot point to the same file.");
2718
2719 return -1;
2720 }
2721
2722 // check for outfile vs. cached wordlists
2723
2724 if (user_options->attack_mode == ATTACK_MODE_STRAIGHT)
2725 {
2726 for (int i = 0; i < user_options_extra->hc_workc; i++)
2727 {
2728 char *wlfile = user_options_extra->hc_workv[i];
2729
2730 if (hc_same_files (outfile_ctx->filename, wlfile) == true)
2731 {
2732 event_log_error (hashcat_ctx, "Outfile and wordlist cannot point to the same file.");
2733
2734 return -1;
2735 }
2736 }
2737 }
2738 else if (user_options->attack_mode == ATTACK_MODE_COMBI)
2739 {
2740 if (user_options_extra->hc_workc == 2)
2741 {
2742 char *dictfile1 = user_options_extra->hc_workv[0];
2743 char *dictfile2 = user_options_extra->hc_workv[1];
2744
2745 if (hc_same_files (outfile_ctx->filename, dictfile1) == true)
2746 {
2747 event_log_error (hashcat_ctx, "Outfile and wordlist cannot point to the same file.");
2748
2749 return -1;
2750 }
2751
2752 if (hc_same_files (outfile_ctx->filename, dictfile2) == true)
2753 {
2754 event_log_error (hashcat_ctx, "Outfile and wordlist cannot point to the same file.");
2755
2756 return -1;
2757 }
2758 }
2759 }
2760 else if (user_options->attack_mode == ATTACK_MODE_HYBRID1)
2761 {
2762 if (user_options_extra->hc_workc == 2)
2763 {
2764 char *wlfile = user_options_extra->hc_workv[0];
2765
2766 if (hc_same_files (outfile_ctx->filename, wlfile) == true)
2767 {
2768 event_log_error (hashcat_ctx, "Outfile and wordlist cannot point to the same file.");
2769
2770 return -1;
2771 }
2772 }
2773 }
2774 else if (user_options->attack_mode == ATTACK_MODE_HYBRID2)
2775 {
2776 if (user_options_extra->hc_workc == 2)
2777 {
2778 char *wlfile = user_options_extra->hc_workv[1];
2779
2780 if (hc_same_files (outfile_ctx->filename, wlfile) == true)
2781 {
2782 event_log_error (hashcat_ctx, "Outfile and wordlist cannot point to the same file.");
2783
2784 return -1;
2785 }
2786 }
2787 }
2788 else if (user_options->attack_mode == ATTACK_MODE_ASSOCIATION)
2789 {
2790 for (int i = 0; i < user_options_extra->hc_workc; i++)
2791 {
2792 char *wlfile = user_options_extra->hc_workv[i];
2793
2794 if (hc_same_files (outfile_ctx->filename, wlfile) == true)
2795 {
2796 event_log_error (hashcat_ctx, "Outfile and wordlist cannot point to the same file.");
2797
2798 return -1;
2799 }
2800 }
2801 }
2802
2803 // pidfile
2804
2805 if (hc_path_exist (pidfile_ctx->filename) == true)
2806 {
2807 if (hc_path_is_directory (pidfile_ctx->filename) == true)
2808 {
2809 event_log_error (hashcat_ctx, "%s: A directory cannot be used as a pidfile argument.", pidfile_ctx->filename);
2810
2811 return -1;
2812 }
2813
2814 if (hc_path_write (pidfile_ctx->filename) == false)
2815 {
2816 event_log_error (hashcat_ctx, "%s: %s", pidfile_ctx->filename, strerror (errno));
2817
2818 return -1;
2819 }
2820 }
2821 else
2822 {
2823 if (hc_path_create (pidfile_ctx->filename) == false)
2824 {
2825 event_log_error (hashcat_ctx, "%s: %s", pidfile_ctx->filename, strerror (errno));
2826
2827 return -1;
2828 }
2829 }
2830
2831 // potfile
2832
2833 if (potfile_ctx->enabled == true)
2834 {
2835 if (hc_path_exist (potfile_ctx->filename) == true)
2836 {
2837 if (hc_path_is_directory (potfile_ctx->filename) == true)
2838 {
2839 event_log_error (hashcat_ctx, "%s: A directory cannot be used as a potfile argument.", potfile_ctx->filename);
2840
2841 return -1;
2842 }
2843
2844 if (hc_path_write (potfile_ctx->filename) == false)
2845 {
2846 event_log_error (hashcat_ctx, "%s: %s", potfile_ctx->filename, strerror (errno));
2847
2848 return -1;
2849 }
2850 }
2851 else
2852 {
2853 if (hc_path_create (potfile_ctx->filename) == false)
2854 {
2855 event_log_error (hashcat_ctx, "%s: %s", potfile_ctx->filename, strerror (errno));
2856
2857 return -1;
2858 }
2859 }
2860 }
2861
2862 // dictstat
2863
2864 if (dictstat_ctx->enabled == true)
2865 {
2866 if (hc_path_exist (dictstat_ctx->filename) == true)
2867 {
2868 if (hc_path_is_directory (dictstat_ctx->filename) == true)
2869 {
2870 event_log_error (hashcat_ctx, "%s: A directory cannot be used as a dictstat argument.", dictstat_ctx->filename);
2871
2872 return -1;
2873 }
2874
2875 if (hc_path_write (dictstat_ctx->filename) == false)
2876 {
2877 event_log_error (hashcat_ctx, "%s: %s", dictstat_ctx->filename, strerror (errno));
2878
2879 return -1;
2880 }
2881 }
2882 else
2883 {
2884 if (hc_path_create (dictstat_ctx->filename) == false)
2885 {
2886 event_log_error (hashcat_ctx, "%s: %s", dictstat_ctx->filename, strerror (errno));
2887
2888 return -1;
2889 }
2890 }
2891 }
2892
2893 // single kernel and module existence check to detect "7z e" errors
2894
2895 char *modulefile = (char *) hcmalloc (HCBUFSIZ_TINY);
2896
2897 module_filename (folder_config, 0, modulefile, HCBUFSIZ_TINY);
2898
2899 if (hc_path_exist (modulefile) == false)
2900 {
2901 event_log_error (hashcat_ctx, "%s: %s", modulefile, strerror (errno));
2902
2903 event_log_warning (hashcat_ctx, "If you are using the hashcat binary package, this may be an extraction issue.");
2904 event_log_warning (hashcat_ctx, "For example, using \"7z e\" instead of using \"7z x\".");
2905 event_log_warning (hashcat_ctx, NULL);
2906
2907 hcfree (modulefile);
2908
2909 return -1;
2910 }
2911
2912 hcfree (modulefile);
2913
2914 const bool quiet_save = user_options->quiet;
2915
2916 user_options->quiet = true;
2917
2918 const int rc = hashconfig_init (hashcat_ctx);
2919
2920 user_options->quiet = quiet_save;
2921
2922 if (rc == -1) return -1;
2923
2924 hashconfig_destroy (hashcat_ctx);
2925
2926 // same check but for an backend kernel
2927
2928 char *kernelfile = (char *) hcmalloc (HCBUFSIZ_TINY);
2929
2930 generate_source_kernel_filename (false, ATTACK_EXEC_OUTSIDE_KERNEL, ATTACK_KERN_STRAIGHT, 400, 0, folder_config->shared_dir, kernelfile);
2931
2932 if (hc_path_read (kernelfile) == false)
2933 {
2934 event_log_error (hashcat_ctx, "%s: %s", kernelfile, strerror (errno));
2935
2936 event_log_warning (hashcat_ctx, "If you are using the hashcat binary package, this may be an extraction issue.");
2937 event_log_warning (hashcat_ctx, "For example, using \"7z e\" instead of using \"7z x\".");
2938 event_log_warning (hashcat_ctx, NULL);
2939
2940 hcfree (kernelfile);
2941
2942 return -1;
2943 }
2944
2945 hcfree (kernelfile);
2946
2947 // loopback - can't check at this point
2948
2949 // tuning file check already done
2950
2951 // debugfile check already done
2952
2953 // dictstat
2954
2955 if (user_options->keyboard_layout_mapping != NULL)
2956 {
2957 if (hc_path_exist (user_options->keyboard_layout_mapping) == true)
2958 {
2959 if (hc_path_read (user_options->keyboard_layout_mapping) == false)
2960 {
2961 event_log_error (hashcat_ctx, "%s: %s", user_options->keyboard_layout_mapping, strerror (errno));
2962
2963 return -1;
2964 }
2965 }
2966 else
2967 {
2968 event_log_error (hashcat_ctx, "%s: %s", user_options->keyboard_layout_mapping, strerror (errno));
2969
2970 return -1;
2971 }
2972 }
2973
2974 /**
2975 * default building options
2976 */
2977
2978 /* temporary disabled due to https://github.com/hashcat/hashcat/issues/2379
2979 if (chdir (folder_config->cpath_real) == -1)
2980 {
2981 event_log_error (hashcat_ctx, "%s: %s", folder_config->cpath_real, strerror (errno));
2982
2983 return -1;
2984 }
2985 */
2986
2987 // include check
2988 // this test needs to be done manually because of macOS opencl runtime
2989 // if there's a problem with permission, its not reporting back and erroring out silently
2990
2991 const char *files_names[] =
2992 {
2993 "inc_cipher_aes.cl",
2994 "inc_cipher_serpent.cl",
2995 "inc_cipher_twofish.cl",
2996 "inc_common.cl",
2997 "inc_comp_multi_bs.cl",
2998 "inc_comp_multi.cl",
2999 "inc_comp_single_bs.cl",
3000 "inc_comp_single.cl",
3001 "inc_rp_optimized.cl",
3002 "inc_rp_optimized.h",
3003 "inc_simd.cl",
3004 "inc_scalar.cl",
3005 "inc_types.h",
3006 "inc_vendor.h",
3007 NULL
3008 };
3009
3010 for (int i = 0; files_names[i] != NULL; i++)
3011 {
3012 char *temp_filename = NULL;
3013
3014 hc_asprintf (&temp_filename, "%s/%s", folder_config->cpath_real, files_names[i]);
3015
3016 if (hc_path_read (temp_filename) == false)
3017 {
3018 event_log_error (hashcat_ctx, "%s: %s", temp_filename, strerror (errno));
3019
3020 hcfree (temp_filename);
3021
3022 return -1;
3023 }
3024
3025 hcfree (temp_filename);
3026 }
3027
3028 // return back to the folder we came from initially (workaround)
3029
3030 /* temporary disabled due to https://github.com/hashcat/hashcat/issues/2379
3031 #if defined (_WIN)
3032 if (chdir ("..") == -1)
3033 {
3034 event_log_error (hashcat_ctx, "%s: %s", "..", strerror (errno));
3035
3036 return -1;
3037 }
3038 #else
3039 if (chdir (folder_config->cwd) == -1)
3040 {
3041 event_log_error (hashcat_ctx, "%s: %s", folder_config->cwd, strerror (errno));
3042
3043 return -1;
3044 }
3045 #endif
3046 */
3047
3048 return 0;
3049 }
3050
user_options_logger(hashcat_ctx_t * hashcat_ctx)3051 void user_options_logger (hashcat_ctx_t *hashcat_ctx)
3052 {
3053 user_options_t *user_options = hashcat_ctx->user_options;
3054 logfile_ctx_t *logfile_ctx = hashcat_ctx->logfile_ctx;
3055
3056 #ifdef WITH_BRAIN
3057 logfile_top_string (user_options->brain_session_whitelist);
3058 #endif
3059 logfile_top_string (user_options->cpu_affinity);
3060 logfile_top_string (user_options->custom_charset_1);
3061 logfile_top_string (user_options->custom_charset_2);
3062 logfile_top_string (user_options->custom_charset_3);
3063 logfile_top_string (user_options->custom_charset_4);
3064 logfile_top_string (user_options->debug_file);
3065 logfile_top_string (user_options->encoding_from);
3066 logfile_top_string (user_options->encoding_to);
3067 logfile_top_string (user_options->induction_dir);
3068 logfile_top_string (user_options->keyboard_layout_mapping);
3069 logfile_top_string (user_options->markov_hcstat2);
3070 logfile_top_string (user_options->backend_devices);
3071 logfile_top_string (user_options->opencl_device_types);
3072 logfile_top_string (user_options->outfile);
3073 logfile_top_string (user_options->outfile_check_dir);
3074 logfile_top_string (user_options->potfile_path);
3075 logfile_top_string (user_options->restore_file_path);
3076 logfile_top_string (user_options->rp_files[0]);
3077 logfile_top_string (user_options->rp_gen_func_sel);
3078 logfile_top_string (user_options->rule_buf_l);
3079 logfile_top_string (user_options->rule_buf_r);
3080 logfile_top_string (user_options->session);
3081 logfile_top_string (user_options->separator);
3082 logfile_top_string (user_options->truecrypt_keyfiles);
3083 logfile_top_string (user_options->veracrypt_keyfiles);
3084 #ifdef WITH_BRAIN
3085 logfile_top_string (user_options->brain_host);
3086 #endif
3087 logfile_top_uint64 (user_options->limit);
3088 logfile_top_uint64 (user_options->skip);
3089 logfile_top_uint (user_options->attack_mode);
3090 logfile_top_uint (user_options->benchmark);
3091 logfile_top_uint (user_options->benchmark_all);
3092 logfile_top_uint (user_options->bitmap_max);
3093 logfile_top_uint (user_options->bitmap_min);
3094 logfile_top_uint (user_options->debug_mode);
3095 logfile_top_uint (user_options->hash_info);
3096 logfile_top_uint (user_options->force);
3097 logfile_top_uint (user_options->hwmon_disable);
3098 logfile_top_uint (user_options->hwmon_temp_abort);
3099 logfile_top_uint (user_options->hash_mode);
3100 logfile_top_uint (user_options->hex_charset);
3101 logfile_top_uint (user_options->hex_salt);
3102 logfile_top_uint (user_options->hex_wordlist);
3103 logfile_top_uint (user_options->hook_threads);
3104 logfile_top_uint (user_options->identify);
3105 logfile_top_uint (user_options->increment);
3106 logfile_top_uint (user_options->increment_max);
3107 logfile_top_uint (user_options->increment_min);
3108 logfile_top_uint (user_options->keep_guessing);
3109 logfile_top_uint (user_options->kernel_accel);
3110 logfile_top_uint (user_options->kernel_loops);
3111 logfile_top_uint (user_options->kernel_threads);
3112 logfile_top_uint (user_options->keyspace);
3113 logfile_top_uint (user_options->left);
3114 logfile_top_uint (user_options->logfile_disable);
3115 logfile_top_uint (user_options->loopback);
3116 logfile_top_uint (user_options->machine_readable);
3117 logfile_top_uint (user_options->markov_classic);
3118 logfile_top_uint (user_options->markov_disable);
3119 logfile_top_uint (user_options->markov_inverse);
3120 logfile_top_uint (user_options->markov_threshold);
3121 logfile_top_uint (user_options->multiply_accel_disable);
3122 logfile_top_uint (user_options->backend_info);
3123 logfile_top_uint (user_options->backend_vector_width);
3124 logfile_top_uint (user_options->optimized_kernel_enable);
3125 logfile_top_uint (user_options->outfile_autohex);
3126 logfile_top_uint (user_options->outfile_check_timer);
3127 logfile_top_uint (user_options->outfile_format);
3128 logfile_top_uint (user_options->wordlist_autohex_disable);
3129 logfile_top_uint (user_options->potfile_disable);
3130 logfile_top_uint (user_options->progress_only);
3131 logfile_top_uint (user_options->quiet);
3132 logfile_top_uint (user_options->remove);
3133 logfile_top_uint (user_options->remove_timer);
3134 logfile_top_uint (user_options->restore);
3135 logfile_top_uint (user_options->restore_disable);
3136 logfile_top_uint (user_options->restore_timer);
3137 logfile_top_uint (user_options->rp_files_cnt);
3138 logfile_top_uint (user_options->rp_gen);
3139 logfile_top_uint (user_options->rp_gen_func_max);
3140 logfile_top_uint (user_options->rp_gen_func_min);
3141 logfile_top_uint (user_options->rp_gen_seed);
3142 logfile_top_uint (user_options->runtime);
3143 logfile_top_uint (user_options->scrypt_tmto);
3144 logfile_top_uint (user_options->segment_size);
3145 logfile_top_uint (user_options->self_test_disable);
3146 logfile_top_uint (user_options->slow_candidates);
3147 logfile_top_uint (user_options->show);
3148 logfile_top_uint (user_options->speed_only);
3149 logfile_top_uint (user_options->spin_damp);
3150 logfile_top_uint (user_options->status);
3151 logfile_top_uint (user_options->status_json);
3152 logfile_top_uint (user_options->status_timer);
3153 logfile_top_uint (user_options->stdout_flag);
3154 logfile_top_uint (user_options->usage);
3155 logfile_top_uint (user_options->username);
3156 logfile_top_uint (user_options->veracrypt_pim_start);
3157 logfile_top_uint (user_options->veracrypt_pim_stop);
3158 logfile_top_uint (user_options->version);
3159 logfile_top_uint (user_options->workload_profile);
3160 #ifdef WITH_BRAIN
3161 logfile_top_uint (user_options->brain_client);
3162 logfile_top_uint (user_options->brain_client_features);
3163 logfile_top_uint (user_options->brain_server);
3164 logfile_top_uint (user_options->brain_server_timer);
3165 logfile_top_uint (user_options->brain_port);
3166 logfile_top_uint (user_options->brain_session);
3167 #endif
3168 }
3169