From b457f402c6c89c77e81eb7b70ff126b21afdfbf1 Mon Sep 17 00:00:00 2001 From: Jens Steube Date: Mon, 26 Nov 2018 12:39:17 +0100 Subject: [PATCH] Fix output of mapped password in status screen --- src/hashes.c | 133 -------------------------------------------------- src/outfile.c | 129 ++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 129 insertions(+), 133 deletions(-) diff --git a/src/hashes.c b/src/hashes.c index 46effb299..523cd3048 100644 --- a/src/hashes.c +++ b/src/hashes.c @@ -130,129 +130,6 @@ int sort_by_hash_no_salt (const void *v1, const void *v2, void *v3) return sort_by_digest_p0p1 (d1, d2, v3); } -int find_keyboard_layout_map (const u32 search, const int search_len, keyboard_layout_mapping_t *s_keyboard_layout_mapping, const int keyboard_layout_mapping_cnt) -{ - for (int idx = 0; idx < keyboard_layout_mapping_cnt; idx++) - { - const u32 src_char = s_keyboard_layout_mapping[idx].src_char; - const int src_len = s_keyboard_layout_mapping[idx].src_len; - - if (src_len == search_len) - { - const u32 mask = 0xffffffff >> ((4 - search_len) * 8); - - if ((src_char & mask) == (search & mask)) return idx; - } - } - - return -1; -} - -int execute_keyboard_layout_mapping (u32 plain_buf[64], const int plain_len, keyboard_layout_mapping_t *s_keyboard_layout_mapping, const int keyboard_layout_mapping_cnt) -{ - u32 out_buf[16] = { 0 }; - - u8 *out_ptr = (u8 *) out_buf; - - int out_len = 0; - - u8 *plain_ptr = (u8 *) plain_buf; - - int plain_pos = 0; - - while (plain_pos < plain_len) - { - u32 src0 = 0; - u32 src1 = 0; - u32 src2 = 0; - u32 src3 = 0; - - #define MIN(a,b) (((a) < (b)) ? (a) : (b)) - - const int rem = MIN (plain_len - plain_pos, 4); - - #undef MIN - - if (rem > 0) src0 = plain_ptr[plain_pos + 0]; - if (rem > 1) src1 = plain_ptr[plain_pos + 1]; - if (rem > 2) src2 = plain_ptr[plain_pos + 2]; - if (rem > 3) src3 = plain_ptr[plain_pos + 3]; - - const u32 src = (src0 << 0) - | (src1 << 8) - | (src2 << 16) - | (src3 << 24); - - int src_len; - - for (src_len = rem; src_len > 0; src_len--) - { - const int idx = find_keyboard_layout_map (src, src_len, s_keyboard_layout_mapping, keyboard_layout_mapping_cnt); - - if (idx == -1) continue; - - u32 dst_char = s_keyboard_layout_mapping[idx].dst_char; - int dst_len = s_keyboard_layout_mapping[idx].dst_len; - - switch (dst_len) - { - case 1: - out_ptr[out_len++] = (dst_char >> 0) & 0xff; - break; - case 2: - out_ptr[out_len++] = (dst_char >> 0) & 0xff; - out_ptr[out_len++] = (dst_char >> 8) & 0xff; - break; - case 3: - out_ptr[out_len++] = (dst_char >> 0) & 0xff; - out_ptr[out_len++] = (dst_char >> 8) & 0xff; - out_ptr[out_len++] = (dst_char >> 16) & 0xff; - break; - case 4: - out_ptr[out_len++] = (dst_char >> 0) & 0xff; - out_ptr[out_len++] = (dst_char >> 8) & 0xff; - out_ptr[out_len++] = (dst_char >> 16) & 0xff; - out_ptr[out_len++] = (dst_char >> 24) & 0xff; - break; - } - - plain_pos += src_len; - - break; - } - - // not matched, keep original - - if (src_len == 0) - { - out_ptr[out_len] = plain_ptr[plain_pos]; - - out_len++; - - plain_pos++; - } - } - - plain_buf[ 0] = out_buf[ 0]; - plain_buf[ 1] = out_buf[ 1]; - plain_buf[ 2] = out_buf[ 2]; - plain_buf[ 3] = out_buf[ 3]; - plain_buf[ 4] = out_buf[ 4]; - plain_buf[ 5] = out_buf[ 5]; - plain_buf[ 6] = out_buf[ 6]; - plain_buf[ 7] = out_buf[ 7]; - plain_buf[ 8] = out_buf[ 8]; - plain_buf[ 9] = out_buf[ 9]; - plain_buf[10] = out_buf[10]; - plain_buf[11] = out_buf[11]; - plain_buf[12] = out_buf[12]; - plain_buf[13] = out_buf[13]; - plain_buf[14] = out_buf[14]; - plain_buf[15] = out_buf[15]; - - return out_len; -} - int save_hash (hashcat_ctx_t *hashcat_ctx) { hashes_t *hashes = hashcat_ctx->hashes; @@ -425,16 +302,6 @@ void check_hash (hashcat_ctx_t *hashcat_ctx, hc_device_param_t *device_param, pl strncpy ((char *) plain_ptr, (char *) temp_ptr, sizeof (plain_buf)); } - // truecrypt and veracrypt boot only: - // we do some kernel internal substituations, so we need to do that here as well, if it cracks - - if (hashconfig->opts_type & OPTS_TYPE_KEYBOARD_MAPPING) - { - tc_t *tc = (tc_t *) hashes->esalts_buf; - - plain_len = execute_keyboard_layout_mapping (plain_buf, plain_len, tc->keyboard_layout_mapping_buf, tc->keyboard_layout_mapping_cnt); - } - // crackpos u64 crackpos = 0; diff --git a/src/outfile.c b/src/outfile.c index db3c1f5a4..ca741eaa9 100644 --- a/src/outfile.c +++ b/src/outfile.c @@ -19,6 +19,125 @@ #include "outfile.h" #include "locking.h" +static int find_keyboard_layout_map (const u32 search, const int search_len, keyboard_layout_mapping_t *s_keyboard_layout_mapping, const int keyboard_layout_mapping_cnt) +{ + for (int idx = 0; idx < keyboard_layout_mapping_cnt; idx++) + { + const u32 src_char = s_keyboard_layout_mapping[idx].src_char; + const int src_len = s_keyboard_layout_mapping[idx].src_len; + + if (src_len == search_len) + { + const u32 mask = 0xffffffff >> ((4 - search_len) * 8); + + if ((src_char & mask) == (search & mask)) return idx; + } + } + + return -1; +} + +static int execute_keyboard_layout_mapping (u32 plain_buf[64], const int plain_len, keyboard_layout_mapping_t *s_keyboard_layout_mapping, const int keyboard_layout_mapping_cnt) +{ + u32 out_buf[16] = { 0 }; + + u8 *out_ptr = (u8 *) out_buf; + + int out_len = 0; + + u8 *plain_ptr = (u8 *) plain_buf; + + int plain_pos = 0; + + while (plain_pos < plain_len) + { + u32 src0 = 0; + u32 src1 = 0; + u32 src2 = 0; + u32 src3 = 0; + + const int rem = MIN (plain_len - plain_pos, 4); + + if (rem > 0) src0 = plain_ptr[plain_pos + 0]; + if (rem > 1) src1 = plain_ptr[plain_pos + 1]; + if (rem > 2) src2 = plain_ptr[plain_pos + 2]; + if (rem > 3) src3 = plain_ptr[plain_pos + 3]; + + const u32 src = (src0 << 0) + | (src1 << 8) + | (src2 << 16) + | (src3 << 24); + + int src_len; + + for (src_len = rem; src_len > 0; src_len--) + { + const int idx = find_keyboard_layout_map (src, src_len, s_keyboard_layout_mapping, keyboard_layout_mapping_cnt); + + if (idx == -1) continue; + + u32 dst_char = s_keyboard_layout_mapping[idx].dst_char; + int dst_len = s_keyboard_layout_mapping[idx].dst_len; + + switch (dst_len) + { + case 1: + out_ptr[out_len++] = (dst_char >> 0) & 0xff; + break; + case 2: + out_ptr[out_len++] = (dst_char >> 0) & 0xff; + out_ptr[out_len++] = (dst_char >> 8) & 0xff; + break; + case 3: + out_ptr[out_len++] = (dst_char >> 0) & 0xff; + out_ptr[out_len++] = (dst_char >> 8) & 0xff; + out_ptr[out_len++] = (dst_char >> 16) & 0xff; + break; + case 4: + out_ptr[out_len++] = (dst_char >> 0) & 0xff; + out_ptr[out_len++] = (dst_char >> 8) & 0xff; + out_ptr[out_len++] = (dst_char >> 16) & 0xff; + out_ptr[out_len++] = (dst_char >> 24) & 0xff; + break; + } + + plain_pos += src_len; + + break; + } + + // not matched, keep original + + if (src_len == 0) + { + out_ptr[out_len] = plain_ptr[plain_pos]; + + out_len++; + + plain_pos++; + } + } + + plain_buf[ 0] = out_buf[ 0]; + plain_buf[ 1] = out_buf[ 1]; + plain_buf[ 2] = out_buf[ 2]; + plain_buf[ 3] = out_buf[ 3]; + plain_buf[ 4] = out_buf[ 4]; + plain_buf[ 5] = out_buf[ 5]; + plain_buf[ 6] = out_buf[ 6]; + plain_buf[ 7] = out_buf[ 7]; + plain_buf[ 8] = out_buf[ 8]; + plain_buf[ 9] = out_buf[ 9]; + plain_buf[10] = out_buf[10]; + plain_buf[11] = out_buf[11]; + plain_buf[12] = out_buf[12]; + plain_buf[13] = out_buf[13]; + plain_buf[14] = out_buf[14]; + plain_buf[15] = out_buf[15]; + + return out_len; +} + int build_plain (hashcat_ctx_t *hashcat_ctx, hc_device_param_t *device_param, plain_t *plain, u32 *plain_buf, int *out_len) { const combinator_ctx_t *combinator_ctx = hashcat_ctx->combinator_ctx; @@ -241,6 +360,16 @@ int build_plain (hashcat_ctx_t *hashcat_ctx, hc_device_param_t *device_param, pl if (plain_len > (int) hashconfig->pw_max) plain_len = MIN (plain_len, (int) pw_max); + // truecrypt and veracrypt boot only: + // we do some kernel internal substituations, so we need to do that here as well, if it cracks + + if (hashconfig->opts_type & OPTS_TYPE_KEYBOARD_MAPPING) + { + tc_t *tc = (tc_t *) hashes->esalts_buf; + + plain_len = execute_keyboard_layout_mapping (plain_buf, plain_len, tc->keyboard_layout_mapping_buf, tc->keyboard_layout_mapping_cnt); + } + plain_ptr[plain_len] = 0; *out_len = plain_len;