Merge pull request #1975 from Chick3nman/master

Add --status-json flag
pull/1977/head
Jens Steube 5 years ago committed by GitHub
commit cf8c815caf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -189,7 +189,7 @@ _hashcat ()
local BUILD_IN_CHARSETS='?l ?u ?d ?a ?b ?s ?h ?H'
local SHORT_OPTS="-m -a -V -v -h -b -t -o -p -c -d -w -n -u -j -k -r -g -1 -2 -3 -4 -i -I -s -l -O -S -z"
local LONG_OPTS="--hash-type --attack-mode --version --help --quiet --benchmark --benchmark-all --hex-salt --hex-wordlist --hex-charset --force --status --status-timer --machine-readable --loopback --markov-hcstat2 --markov-disable --markov-classic --markov-threshold --runtime --session --speed-only --progress-only --restore --restore-file-path --restore-disable --outfile --outfile-format --outfile-autohex-disable --outfile-check-timer --outfile-check-dir --wordlist-autohex-disable --separator --show --left --username --remove --remove-timer --potfile-disable --potfile-path --debug-mode --debug-file --induction-dir --segment-size --bitmap-min --bitmap-max --cpu-affinity --example-hashes --opencl-info --opencl-devices --opencl-platforms --opencl-device-types --opencl-vector-width --workload-profile --kernel-accel --kernel-loops --kernel-threads --spin-damp --hwmon-disable --hwmon-temp-abort --skip --limit --keyspace --rule-left --rule-right --rules-file --generate-rules --generate-rules-func-min --generate-rules-func-max --generate-rules-seed --custom-charset1 --custom-charset2 --custom-charset3 --custom-charset4 --increment --increment-min --increment-max --logfile-disable --scrypt-tmto --keyboard-layout-mapping --truecrypt-keyfiles --veracrypt-keyfiles --veracrypt-pim-start --veracrypt-pim-stop --stdout --keep-guessing --hccapx-message-pair --nonce-error-corrections --encoding-from --encoding-to --optimized-kernel-enable --self-test-disable --slow-candidates --brain-server --brain-client --brain-client-features --brain-host --brain-port --brain-session --brain-session-whitelist --brain-password"
local LONG_OPTS="--hash-type --attack-mode --version --help --quiet --benchmark --benchmark-all --hex-salt --hex-wordlist --hex-charset --force --status --status-json --status-timer --machine-readable --loopback --markov-hcstat2 --markov-disable --markov-classic --markov-threshold --runtime --session --speed-only --progress-only --restore --restore-file-path --restore-disable --outfile --outfile-format --outfile-autohex-disable --outfile-check-timer --outfile-check-dir --wordlist-autohex-disable --separator --show --left --username --remove --remove-timer --potfile-disable --potfile-path --debug-mode --debug-file --induction-dir --segment-size --bitmap-min --bitmap-max --cpu-affinity --example-hashes --opencl-info --opencl-devices --opencl-platforms --opencl-device-types --opencl-vector-width --workload-profile --kernel-accel --kernel-loops --kernel-threads --spin-damp --hwmon-disable --hwmon-temp-abort --skip --limit --keyspace --rule-left --rule-right --rules-file --generate-rules --generate-rules-func-min --generate-rules-func-max --generate-rules-seed --custom-charset1 --custom-charset2 --custom-charset3 --custom-charset4 --increment --increment-min --increment-max --logfile-disable --scrypt-tmto --keyboard-layout-mapping --truecrypt-keyfiles --veracrypt-keyfiles --veracrypt-pim-start --veracrypt-pim-stop --stdout --keep-guessing --hccapx-message-pair --nonce-error-corrections --encoding-from --encoding-to --optimized-kernel-enable --self-test-disable --slow-candidates --brain-server --brain-client --brain-client-features --brain-host --brain-port --brain-session --brain-session-whitelist --brain-password"
local OPTIONS="-m -a -t -o -p -c -d -w -n -u -j -k -r -g -1 -2 -3 -4 -s -l --hash-type --attack-mode --status-timer --markov-hcstat2 --markov-threshold --runtime --session --timer --outfile --outfile-format --outfile-check-timer --outfile-check-dir --separator --remove-timer --potfile-path --restore-file-path --debug-mode --debug-file --induction-dir --segment-size --bitmap-min --bitmap-max --cpu-affinity --opencl-devices --opencl-platforms --opencl-device-types --opencl-vector-width --workload-profile --kernel-accel --kernel-loops --kernel-threads --spin-damp --hwmon-temp-abort --skip --limit --rule-left --rule-right --rules-file --generate-rules --generate-rules-func-min --generate-rules-func-max --generate-rules-seed --custom-charset1 --custom-charset2 --custom-charset3 --custom-charset4 --increment-min --increment-max --scrypt-tmto --keyboard-layout-mapping --truecrypt-keyfiles --veracrypt-keyfiles --veracrypt-pim-start --veracrypt-pim-stop --hccapx-message-pair --nonce-error-corrections --encoding-from --encoding-to --brain-client-features --brain-host --brain-password --brain-port --brain-session --brain-whitelist-session --stdin-timeout-abort"
COMPREPLY=()

@ -621,6 +621,7 @@ typedef enum user_options_defaults
SPEED_ONLY = false,
SPIN_DAMP = 8,
STATUS = false,
STATUS_JSON = false,
STATUS_TIMER = 10,
STDIN_TIMEOUT_ABORT = 120,
STDOUT_FLAG = false,
@ -728,17 +729,18 @@ typedef enum user_options_map
IDX_SPEED_ONLY = 0xff3d,
IDX_SPIN_DAMP = 0xff3e,
IDX_STATUS = 0xff3f,
IDX_STATUS_TIMER = 0xff40,
IDX_STDOUT_FLAG = 0xff41,
IDX_STDIN_TIMEOUT_ABORT = 0xff42,
IDX_TRUECRYPT_KEYFILES = 0xff43,
IDX_USERNAME = 0xff44,
IDX_VERACRYPT_KEYFILES = 0xff45,
IDX_VERACRYPT_PIM_START = 0xff46,
IDX_VERACRYPT_PIM_STOP = 0xff47,
IDX_STATUS_JSON = 0xff40,
IDX_STATUS_TIMER = 0xff41,
IDX_STDOUT_FLAG = 0xff42,
IDX_STDIN_TIMEOUT_ABORT = 0xff43,
IDX_TRUECRYPT_KEYFILES = 0xff44,
IDX_USERNAME = 0xff45,
IDX_VERACRYPT_KEYFILES = 0xff46,
IDX_VERACRYPT_PIM_START = 0xff47,
IDX_VERACRYPT_PIM_STOP = 0xff48,
IDX_VERSION_LOWER = 'v',
IDX_VERSION = 'V',
IDX_WORDLIST_AUTOHEX_DISABLE = 0xff48,
IDX_WORDLIST_AUTOHEX_DISABLE = 0xff49,
IDX_WORKLOAD_PROFILE = 'w',
} user_options_map_t;
@ -1727,6 +1729,7 @@ typedef struct user_options
bool slow_candidates;
bool speed_only;
bool status;
bool status_json;
bool stdout_flag;
bool stdin_timeout_abort_chgd;
bool usage;

@ -722,6 +722,7 @@ void opencl_info_compact (hashcat_ctx_t *hashcat_ctx)
if (user_options->quiet == true) return;
if (user_options->machine_readable == true) return;
if (user_options->status_json == true) return;
cl_uint platforms_cnt = opencl_ctx->platforms_cnt;
cl_platform_id *platforms = opencl_ctx->platforms;
@ -884,6 +885,93 @@ void status_display_machine_readable (hashcat_ctx_t *hashcat_ctx)
hcfree (hashcat_status);
}
void status_display_status_json (hashcat_ctx_t *hashcat_ctx)
{
const hwmon_ctx_t *hwmon_ctx = hashcat_ctx->hwmon_ctx;
const status_ctx_t *status_ctx = hashcat_ctx->status_ctx;
hashcat_status_t *hashcat_status = (hashcat_status_t *) hcmalloc (sizeof (hashcat_status_t));
const int rc_status = hashcat_get_status (hashcat_ctx, hashcat_status);
if (rc_status == -1)
{
hcfree (hashcat_status);
return;
}
time_t time_now;
time (&time_now);
time_t end;
time_t sec_etc = status_get_sec_etc (hashcat_ctx);
if (overflow_check_u64_add (time_now, sec_etc) == false)
{
end = 1;
}
else
{
end = time_now + sec_etc;
}
printf ("{ \"session\": \"%s\",", hashcat_status->session);
printf (" \"status\": %d,", hashcat_status->status_number);
printf (" \"target\": \"%s\",", hashcat_status->hash_target);
printf (" \"progress\": [%" PRIu64 ", %" PRIu64 "],", hashcat_status->progress_cur_relative_skip, hashcat_status->progress_end_relative_skip);
printf (" \"restore_point\": %" PRIu64 ",", hashcat_status->restore_point);
printf (" \"recovered_hashes\": [%d, %d],", hashcat_status->digests_done, hashcat_status->digests_cnt);
printf (" \"recovered_salts\": [%d, %d],", hashcat_status->salts_done, hashcat_status->salts_cnt);
printf (" \"rejected\": %" PRIu64 ",", hashcat_status->progress_rejected);
printf (" \"devices\": [");
int device_num = 0;
for (int device_id = 0; device_id < hashcat_status->device_info_cnt; device_id++)
{
const device_info_t *device_info = hashcat_status->device_info_buf + device_id;
if (device_info->skipped_dev == true) continue;
if (device_info->skipped_warning_dev == true) continue;
if (device_num != 0)
{
printf(",");
}
printf (" { \"device_id\": %d,", device_id + 1);
printf (" \"speed\": %" PRIu64 ",", (u64) (device_info->hashes_msec_dev * 1000));
if (hwmon_ctx->enabled == true)
{
const int temp = hm_get_temperature_with_device_id (hashcat_ctx, device_id);
printf (" \"temp\": %d,", temp);
}
const int util = hm_get_utilization_with_device_id (hashcat_ctx, device_id);
printf (" \"util\": %d }", util);
device_num++;
}
printf (" ],");
printf (" \"time_start\": %" PRIu64 ",", status_ctx->runtime_start);
printf (" \"estimated_stop\": %" PRIu64 " }", end);
hc_fwrite (EOL, strlen (EOL), 1, stdout);
fflush (stdout);
status_status_destroy (hashcat_ctx, hashcat_status);
hcfree (hashcat_status);
}
void status_display (hashcat_ctx_t *hashcat_ctx)
{
const hashconfig_t *hashconfig = hashcat_ctx->hashconfig;
@ -896,6 +984,13 @@ void status_display (hashcat_ctx_t *hashcat_ctx)
return;
}
if (user_options->status_json == true)
{
status_display_status_json (hashcat_ctx);
return;
}
hashcat_status_t *hashcat_status = (hashcat_status_t *) hcmalloc (sizeof (hashcat_status_t));
@ -1561,6 +1656,47 @@ void status_speed_machine_readable (hashcat_ctx_t *hashcat_ctx)
hcfree (hashcat_status);
}
void status_speed_json (hashcat_ctx_t *hashcat_ctx)
{
hashcat_status_t *hashcat_status = (hashcat_status_t *) hcmalloc (sizeof (hashcat_status_t));
const int rc_status = hashcat_get_status (hashcat_ctx, hashcat_status);
if (rc_status == -1)
{
hcfree (hashcat_status);
return;
}
printf ("{ \"devices\": [");
int device_num = 0;
for (int device_id = 0; device_id < hashcat_status->device_info_cnt; device_id++)
{
const device_info_t *device_info = hashcat_status->device_info_buf + device_id;
if (device_info->skipped_dev == true) continue;
if (device_info->skipped_warning_dev == true) continue;
if (device_num != 0)
{
printf(",");
}
printf (" { \"device_id\": %d,", device_id + 1);
printf (" \"speed\": %" PRIu64 " }", (u64) (device_info->hashes_msec_dev_benchmark * 1000));
device_num++;
}
printf(" ] }");
status_status_destroy (hashcat_ctx, hashcat_status);
hcfree (hashcat_status);
}
void status_speed (hashcat_ctx_t *hashcat_ctx)
{
const user_options_t *user_options = hashcat_ctx->user_options;
@ -1571,6 +1707,13 @@ void status_speed (hashcat_ctx_t *hashcat_ctx)
return;
}
if (user_options->status_json == true)
{
status_speed_json (hashcat_ctx);
return;
}
hashcat_status_t *hashcat_status = (hashcat_status_t *) hcmalloc (sizeof (hashcat_status_t));
@ -1638,6 +1781,48 @@ void status_progress_machine_readable (hashcat_ctx_t *hashcat_ctx)
hcfree (hashcat_status);
}
void status_progress_json (hashcat_ctx_t *hashcat_ctx)
{
hashcat_status_t *hashcat_status = (hashcat_status_t *) hcmalloc (sizeof (hashcat_status_t));
const int rc_status = hashcat_get_status (hashcat_ctx, hashcat_status);
if (rc_status == -1)
{
hcfree (hashcat_status);
return;
}
printf ("{ \"devices\": [");
int device_num = 0;
for (int device_id = 0; device_id < hashcat_status->device_info_cnt; device_id++)
{
const device_info_t *device_info = hashcat_status->device_info_buf + device_id;
if (device_info->skipped_dev == true) continue;
if (device_info->skipped_warning_dev == true) continue;
if (device_num != 0)
{
printf(",");
}
printf (" { \"device_id\": %d,", device_id + 1);
printf (" \"progress\": %" PRIu64 ",", device_info->progress_dev);
printf (" \"runtime\": %0.2f }", device_info->runtime_msec_dev);
device_num++;
}
printf(" ] }");
status_status_destroy (hashcat_ctx, hashcat_status);
hcfree (hashcat_status);
}
void status_progress (hashcat_ctx_t *hashcat_ctx)
{
const user_options_t *user_options = hashcat_ctx->user_options;
@ -1648,6 +1833,13 @@ void status_progress (hashcat_ctx_t *hashcat_ctx)
return;
}
if (user_options->status_json == true)
{
status_progress_json (hashcat_ctx);
return;
}
hashcat_status_t *hashcat_status = (hashcat_status_t *) hcmalloc (sizeof (hashcat_status_t));

@ -36,6 +36,7 @@ static const char *const USAGE_BIG_PRE_HASHMODES[] =
" --hex-wordlist | | Assume words in wordlist are given in hex |",
" --force | | Ignore warnings |",
" --status | | Enable automatic update of the status screen |",
" --status-json | | Enable JSON format for status ouput |",
" --status-timer | Num | Sets seconds between status screen updates to X | --status-timer=1",
" --stdin-timeout-abort | Num | Abort if there is no input from stdin for X seconds | --stdin-timeout-abort=300",
" --machine-readable | | Display the status view in a machine-readable format |",

@ -111,6 +111,7 @@ static const struct option long_options[] =
{"speed-only", no_argument, NULL, IDX_SPEED_ONLY},
{"spin-damp", required_argument, NULL, IDX_SPIN_DAMP},
{"status", no_argument, NULL, IDX_STATUS},
{"status-json", no_argument, NULL, IDX_STATUS_JSON},
{"status-timer", required_argument, NULL, IDX_STATUS_TIMER},
{"stdout", no_argument, NULL, IDX_STDOUT_FLAG},
{"stdin-timeout-abort", required_argument, NULL, IDX_STDIN_TIMEOUT_ABORT},
@ -241,6 +242,7 @@ int user_options_init (hashcat_ctx_t *hashcat_ctx)
user_options->speed_only = SPEED_ONLY;
user_options->spin_damp = SPIN_DAMP;
user_options->status = STATUS;
user_options->status_json = STATUS_JSON;
user_options->status_timer = STATUS_TIMER;
user_options->stdin_timeout_abort = STDIN_TIMEOUT_ABORT;
user_options->stdout_flag = STDOUT_FLAG;
@ -390,6 +392,7 @@ int user_options_getopt (hashcat_ctx_t *hashcat_ctx, int argc, char **argv)
case IDX_RESTORE_DISABLE: user_options->restore_disable = true; break;
case IDX_RESTORE_FILE_PATH: user_options->restore_file_path = optarg; break;
case IDX_STATUS: user_options->status = true; break;
case IDX_STATUS_JSON: user_options->status_json = true; break;
case IDX_STATUS_TIMER: user_options->status_timer = hc_strtoul (optarg, NULL, 10); break;
case IDX_MACHINE_READABLE: user_options->machine_readable = true; break;
case IDX_LOOPBACK: user_options->loopback = true; break;
@ -909,12 +912,22 @@ int user_options_sanity (hashcat_ctx_t *hashcat_ctx)
return -1;
}
}
if (user_options->machine_readable == true)
{
if (user_options->status_json == true)
{
event_log_error (hashcat_ctx, "The --status-json flag can not be used with --machine-readable.");
return -1;
}
}
if (user_options->remove_timer_chgd == true)
{
if (user_options->remove == false)
{
event_log_error (hashcat_ctx, "The --remove-timer requires --remove.");
event_log_error (hashcat_ctx, "The --remove-timer flag requires --remove.");
return -1;
}
@ -1106,7 +1119,7 @@ int user_options_sanity (hashcat_ctx_t *hashcat_ctx)
return -1;
}
}
if (user_options->stdin_timeout_abort_chgd == true)
{
if (user_options->attack_mode != ATTACK_MODE_STRAIGHT)
@ -2786,6 +2799,7 @@ void user_options_logger (hashcat_ctx_t *hashcat_ctx)
logfile_top_uint (user_options->speed_only);
logfile_top_uint (user_options->spin_damp);
logfile_top_uint (user_options->status);
logfile_top_uint (user_options->status_json);
logfile_top_uint (user_options->status_timer);
logfile_top_uint (user_options->stdout_flag);
logfile_top_uint (user_options->usage);

Loading…
Cancel
Save