Skip to content

Commit c9b9c7e

Browse files
committed
Count/report hashes removed by --salts or --cost options
Closes #5699
1 parent 00c81af commit c9b9c7e

File tree

3 files changed

+28
-14
lines changed

3 files changed

+28
-14
lines changed

src/john.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1084,7 +1084,7 @@ static void john_load(void)
10841084
}
10851085

10861086
if (options.flags & FLG_PASSWD) {
1087-
int total;
1087+
int total, cracked;
10881088
int i = 0;
10891089

10901090
if (options.flags & FLG_SHOW_CHK) {
@@ -1241,16 +1241,16 @@ static void john_load(void)
12411241
*/
12421242
load_extra_pots(&database, &ldr_load_pot_file);
12431243

1244-
total = ldr_fix_database(&database);
1244+
total = database.password_count;
1245+
cracked = ldr_fix_database(&database);
12451246

12461247
if (database.password_count && options.regen_lost_salts)
12471248
build_fake_salts_for_regen_lost(&database);
12481249

1249-
if (john_main_process && database.password_count < total) {
1250-
int count = total - database.password_count;
1250+
if (john_main_process && cracked) {
12511251
printf("Cracked %d password hash%s%s%s%s, use \"--show\"\n",
1252-
count, count != 1 ? "es" : "",
1253-
loaded_extra_pots ? "" : (count != 1 ? " (are in " : " (is in "),
1252+
cracked, cracked != 1 ? "es" : "",
1253+
loaded_extra_pots ? "" : (cracked != 1 ? " (are in " : " (is in "),
12541254
loaded_extra_pots ? "" : path_expand(options.activepot),
12551255
loaded_extra_pots ? "" : ")");
12561256
}

src/loader.c

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2038,6 +2038,7 @@ static void ldr_fill_user_words(struct db_main *db)
20382038
int ldr_fix_database(struct db_main *db)
20392039
{
20402040
int total = db->password_count;
2041+
int cracked = 0;
20412042

20422043
ldr_init_salts(db);
20432044
MEM_FREE(db->password_hash);
@@ -2047,20 +2048,34 @@ int ldr_fix_database(struct db_main *db)
20472048
MEM_FREE(db->salt_hash);
20482049

20492050
if (!ldr_loading_testdb) {
2051+
FILE *out_file = options.loader.showuncracked ? stderr : stdout;
2052+
20502053
if (db->options->best_pps) {
20512054
ldr_sort_salts(db, 1);
20522055
ldr_filter_n_best_salts(db);
20532056
} else
20542057
ldr_filter_salts(db);
2058+
int filtered = total - db->password_count;
2059+
if (filtered && john_main_process) {
2060+
fprintf(out_file, "Removed %d password hash%s due to --salts\n",
2061+
filtered, filtered != 1 ? "es" : "");
2062+
}
2063+
2064+
total = db->password_count;
20552065
ldr_filter_costs(db);
2066+
filtered = total - db->password_count;
2067+
if (filtered && john_main_process) {
2068+
fprintf(out_file, "Removed %d password hash%s due to --cost\n",
2069+
filtered, filtered != 1 ? "es" : "");
2070+
}
2071+
20562072
total = db->password_count;
20572073
ldr_remove_marked(db);
2074+
cracked = total - db->password_count;
20582075
if (options.loader.showuncracked) {
2059-
int cracked = total - db->password_count;
2060-
if (john_main_process)
2061-
fprintf(stderr, "%s%d password hash%s cracked,"
2062-
" %d left\n", cracked ? "\n" : "", cracked,
2063-
cracked != 1 ? "es" : "", db->password_count);
2076+
fprintf(stderr, "%s%d password hash%s cracked, %d left\n",
2077+
cracked ? "\n" : "", cracked,
2078+
cracked != 1 ? "es" : "", db->password_count);
20642079
exit(0);
20652080
}
20662081
}
@@ -2076,7 +2091,7 @@ int ldr_fix_database(struct db_main *db)
20762091
if (!ldr_loading_testdb && options.seed_per_user)
20772092
ldr_fill_user_words(db);
20782093

2079-
return total;
2094+
return cracked;
20802095
}
20812096

20822097
static int ldr_cracked_hash(char *ciphertext)

src/loader.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -305,8 +305,7 @@ extern void ldr_load_pot_file(struct db_main *db, char *name);
305305
/*
306306
* Finalizes the database after loading, which includes removal of salts and
307307
* hashes that don't meet criteria, as well as of hashes marked as previously
308-
* cracked. Returns the number of hashes that were in the database after
309-
* removal of those not meeting criteria, but before removal of those cracked.
308+
* cracked. Returns the number of hashes that were cracked.
310309
*/
311310
extern int ldr_fix_database(struct db_main *db);
312311

0 commit comments

Comments
 (0)