void logfile_append (hashcat_ctx_t *hashcat_ctx, const char *fmt, ...) { logfile_ctx_t *logfile_ctx = hashcat_ctx->logfile_ctx; if (logfile_ctx->enabled == false) return; FILE *fp = fopen (logfile_ctx->logfile, "ab"); if (fp == NULL) { event_log_error (hashcat_ctx, "%s: %s", logfile_ctx->logfile, strerror (errno)); return; } lock_file (fp); va_list ap; va_start (ap, fmt); vfprintf (fp, fmt, ap); va_end (ap); hc_fwrite (EOL, strlen (EOL), 1, fp); fflush (fp); fclose (fp); }
int dictstat_write (hashcat_ctx_t *hashcat_ctx) { hashconfig_t *hashconfig = hashcat_ctx->hashconfig; dictstat_ctx_t *dictstat_ctx = hashcat_ctx->dictstat_ctx; if (dictstat_ctx->enabled == false) return 0; if (hashconfig->dictstat_disable == true) return 0; FILE *fp = fopen (dictstat_ctx->filename, "wb"); if (fp == NULL) { event_log_error (hashcat_ctx, "%s: %s", dictstat_ctx->filename, strerror (errno)); return -1; } if (lock_file (fp) == -1) { fclose (fp); event_log_error (hashcat_ctx, "%s: %s", dictstat_ctx->filename, strerror (errno)); return -1; } // header u64 v = DICTSTAT_VERSION; u64 z = 0; v = byte_swap_64 (v); z = byte_swap_64 (z); hc_fwrite (&v, sizeof (u64), 1, fp); hc_fwrite (&z, sizeof (u64), 1, fp); // data hc_fwrite (dictstat_ctx->base, sizeof (dictstat_t), dictstat_ctx->cnt, fp); fclose (fp); return 0; }
static void out_flush (out_t *out) { if (out->len == 0) return; hc_fwrite (out->buf, 1, out->len, out->fp); out->len = 0; }
void usage_big_print (const char *progname) { for (int i = 0; USAGE_BIG[i] != NULL; i++) { printf (USAGE_BIG[i], progname); hc_fwrite (EOL, strlen (EOL), 1, stdout); } }
int save_hash (hashcat_ctx_t *hashcat_ctx) { hashes_t *hashes = hashcat_ctx->hashes; hashconfig_t *hashconfig = hashcat_ctx->hashconfig; user_options_t *user_options = hashcat_ctx->user_options; const char *hashfile = hashes->hashfile; char *new_hashfile; char *old_hashfile; hc_asprintf (&new_hashfile, "%s.new", hashfile); hc_asprintf (&old_hashfile, "%s.old", hashfile); unlink (new_hashfile); char separator = hashconfig->separator; FILE *fp = fopen (new_hashfile, "wb"); if (fp == NULL) { event_log_error (hashcat_ctx, "%s: %s", new_hashfile, strerror (errno)); free (new_hashfile); free (old_hashfile); return -1; } if (lock_file (fp) == -1) { fclose (fp); event_log_error (hashcat_ctx, "%s: %s", new_hashfile, strerror (errno)); free (new_hashfile); free (old_hashfile); return -1; } u8 *out_buf = (u8 *) hcmalloc (HCBUFSIZ_LARGE); for (u32 salt_pos = 0; salt_pos < hashes->salts_cnt; salt_pos++) { if (hashes->salts_shown[salt_pos] == 1) continue; salt_t *salt_buf = &hashes->salts_buf[salt_pos]; for (u32 digest_pos = 0; digest_pos < salt_buf->digests_cnt; digest_pos++) { u32 idx = salt_buf->digests_offset + digest_pos; if (hashes->digests_shown[idx] == 1) continue; if (hashconfig->opts_type & OPTS_TYPE_BINARY_HASHFILE) { if ((hashconfig->hash_mode == 2500) || (hashconfig->hash_mode == 2501)) { hccapx_t hccapx; to_hccapx_t (hashcat_ctx, &hccapx, salt_pos, digest_pos); hc_fwrite (&hccapx, sizeof (hccapx_t), 1, fp); } else { // TODO } } else { if (user_options->username == true) { user_t *user = hashes->hash_info[idx]->user; u32 i; for (i = 0; i < user->user_len; i++) fputc (user->user_name[i], fp); fputc (separator, fp); } out_buf[0] = 0; ascii_digest (hashcat_ctx, (char *) out_buf, HCBUFSIZ_LARGE, salt_pos, digest_pos); fprintf (fp, "%s" EOL, out_buf); } } } hcfree (out_buf); fflush (fp); fclose (fp); unlink (old_hashfile); if (rename (hashfile, old_hashfile) != 0) { event_log_error (hashcat_ctx, "Rename file '%s' to '%s': %s", hashfile, old_hashfile, strerror (errno)); free (new_hashfile); free (old_hashfile); return -1; } unlink (hashfile); if (rename (new_hashfile, hashfile) != 0) { event_log_error (hashcat_ctx, "Rename file '%s' to '%s': %s", new_hashfile, hashfile, strerror (errno)); free (new_hashfile); free (old_hashfile); return -1; } unlink (old_hashfile); free (new_hashfile); free (old_hashfile); return 0; }
void status_display_machine_readable (hashcat_ctx_t *hashcat_ctx) { const hwmon_ctx_t *hwmon_ctx = hashcat_ctx->hwmon_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 ("STATUS\t%d\t", hashcat_status->status_number); printf ("SPEED\t"); 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; printf ("%" PRIu64 "\t", (u64) (device_info->hashes_msec_dev * 1000)); // that 1\t is for backward compatibility printf ("1000\t"); } printf ("EXEC_RUNTIME\t"); 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; printf ("%f\t", device_info->exec_msec_dev); } printf ("CURKU\t%" PRIu64 "\t", hashcat_status->restore_point); printf ("PROGRESS\t%" PRIu64 "\t%" PRIu64 "\t", hashcat_status->progress_cur_relative_skip, hashcat_status->progress_end_relative_skip); printf ("RECHASH\t%d\t%d\t", hashcat_status->digests_done, hashcat_status->digests_cnt); printf ("RECSALT\t%d\t%d\t", hashcat_status->salts_done, hashcat_status->salts_cnt); if (hwmon_ctx->enabled == true) { printf ("TEMP\t"); 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; const int temp = hm_get_temperature_with_device_id (hashcat_ctx, device_id); printf ("%d\t", temp); } } printf ("REJECTED\t%" PRIu64 "\t", hashcat_status->progress_rejected); printf ("UTIL\t"); 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; // ok, little cheat here again... const int util = hm_get_utilization_with_device_id (hashcat_ctx, device_id); printf ("%d\t", util); } hc_fwrite (EOL, strlen (EOL), 1, stdout); fflush (stdout); status_status_destroy (hashcat_ctx, hashcat_status); hcfree (hashcat_status); }