1
0
mirror of https://github.com/hashcat/hashcat.git synced 2024-11-26 09:58:16 +00:00

Startup: Check and abort session if outfile and wordlist point to the same file

This commit is contained in:
jsteube 2017-10-10 11:30:20 +02:00
parent 9c832092df
commit 5e6d43107e
4 changed files with 141 additions and 56 deletions

View File

@ -62,6 +62,7 @@
- OpenCL Kernels: Vectorized tons of slow kernels to improve CPU cracking speed
- OpenCL Runtime: Updated AMD ROCm driver version check, warn if version < 1.1
- Startup: Show some attack-specific optimizer constraints on start, eg: minimum and maximum support password- and salt-length
- Startup: Check and abort session if outfile and wordlist point to the same file
- WPA cracking: Improved nonce-error-corrections mode to use a both positive and negative corrections
##

View File

@ -63,4 +63,6 @@ hc_time_t hc_time (hc_time_t *t);
struct tm *hc_gmtime (const hc_time_t *t, MAYBE_UNUSED struct tm *result);
char *hc_ctime (const hc_time_t *t, char *buf, MAYBE_UNUSED const size_t buf_size);
bool hc_same_files (char *file1, char *file2);
#endif // _SHARED_H

View File

@ -462,3 +462,90 @@ char *hc_ctime (const hc_time_t *t, char *buf, MAYBE_UNUSED const size_t buf_siz
return etc;
}
bool hc_same_files (char *file1, char *file2)
{
if ((file1 != NULL) && (file2 != NULL))
{
hc_stat_t tmpstat_file1;
hc_stat_t tmpstat_file2;
int do_check = 0;
FILE *fp;
fp = fopen (file1, "r");
if (fp)
{
if (hc_fstat (fileno (fp), &tmpstat_file1))
{
fclose (fp);
return false;
}
fclose (fp);
do_check++;
}
fp = fopen (file2, "r");
if (fp)
{
if (hc_fstat (fileno (fp), &tmpstat_file2))
{
fclose (fp);
return false;
}
fclose (fp);
do_check++;
}
if (do_check == 2)
{
tmpstat_file1.st_mode = 0;
tmpstat_file1.st_nlink = 0;
tmpstat_file1.st_uid = 0;
tmpstat_file1.st_gid = 0;
tmpstat_file1.st_rdev = 0;
tmpstat_file1.st_atime = 0;
#if defined (STAT_NANOSECONDS_ACCESS_TIME)
tmpstat_file1.STAT_NANOSECONDS_ACCESS_TIME = 0;
#endif
#if defined (_POSIX)
tmpstat_file1.st_blksize = 0;
tmpstat_file1.st_blocks = 0;
#endif
tmpstat_file2.st_mode = 0;
tmpstat_file2.st_nlink = 0;
tmpstat_file2.st_uid = 0;
tmpstat_file2.st_gid = 0;
tmpstat_file2.st_rdev = 0;
tmpstat_file2.st_atime = 0;
#if defined (STAT_NANOSECONDS_ACCESS_TIME)
tmpstat_file2.STAT_NANOSECONDS_ACCESS_TIME = 0;
#endif
#if defined (_POSIX)
tmpstat_file2.st_blksize = 0;
tmpstat_file2.st_blocks = 0;
#endif
if (memcmp (&tmpstat_file1, &tmpstat_file2, sizeof (hc_stat_t)) == 0)
{
return true;
}
}
}
return false;
}

View File

@ -1916,81 +1916,76 @@ int user_options_check_files (hashcat_ctx_t *hashcat_ctx)
}
}
// check for hashfile vs outfile (should not point to the same physical file)
// check for outfile vs. hashfile
if ((user_options_extra->hc_hash != NULL) && (outfile_ctx->filename != NULL))
if (hc_same_files (outfile_ctx->filename, user_options_extra->hc_hash) == true)
{
char *hashfile = user_options_extra->hc_hash;
char *outfile = outfile_ctx->filename;
hc_stat_t tmpstat_outfile;
hc_stat_t tmpstat_hashfile;
memset (&tmpstat_outfile, 0, sizeof (tmpstat_outfile));
memset (&tmpstat_hashfile, 0, sizeof (tmpstat_hashfile));
int do_check = 0;
FILE *tmp_outfile_fp = fopen (outfile, "r");
if (tmp_outfile_fp)
{
if (hc_fstat (fileno (tmp_outfile_fp), &tmpstat_outfile))
{
fclose (tmp_outfile_fp);
event_log_error (hashcat_ctx, "Outfile and hashfile cannot point to the same file.");
return -1;
}
fclose (tmp_outfile_fp);
// check for outfile vs. cached wordlists
do_check++;
if (user_options->attack_mode == ATTACK_MODE_STRAIGHT)
{
for (int i = 0; i < user_options_extra->hc_workc; i++)
{
char *wlfile = user_options_extra->hc_workv[i];
if (hc_same_files (outfile_ctx->filename, wlfile) == true)
{
event_log_error (hashcat_ctx, "Outfile and wordlist cannot point to the same file.");
return -1;
}
FILE *tmp_hashfile_fp = fopen (hashfile, "r");
if (tmp_hashfile_fp)
}
}
else if (user_options->attack_mode == ATTACK_MODE_COMBI)
{
if (hc_fstat (fileno (tmp_hashfile_fp), &tmpstat_hashfile))
if (user_options_extra->hc_workc == 2)
{
fclose (tmp_hashfile_fp);
char *dictfile1 = user_options_extra->hc_workv[0];
char *dictfile2 = user_options_extra->hc_workv[1];
if (hc_same_files (outfile_ctx->filename, dictfile1) == true)
{
event_log_error (hashcat_ctx, "Outfile and wordlist cannot point to the same file.");
return -1;
}
fclose (tmp_hashfile_fp);
if (hc_same_files (outfile_ctx->filename, dictfile2) == true)
{
event_log_error (hashcat_ctx, "Outfile and wordlist cannot point to the same file.");
do_check++;
return -1;
}
if (do_check == 2)
}
}
else if (user_options->attack_mode == ATTACK_MODE_HYBRID1)
{
tmpstat_outfile.st_mode = 0;
tmpstat_outfile.st_nlink = 0;
tmpstat_outfile.st_uid = 0;
tmpstat_outfile.st_gid = 0;
tmpstat_outfile.st_rdev = 0;
tmpstat_outfile.st_atime = 0;
tmpstat_hashfile.st_mode = 0;
tmpstat_hashfile.st_nlink = 0;
tmpstat_hashfile.st_uid = 0;
tmpstat_hashfile.st_gid = 0;
tmpstat_hashfile.st_rdev = 0;
tmpstat_hashfile.st_atime = 0;
#if defined (_POSIX)
tmpstat_outfile.st_blksize = 0;
tmpstat_outfile.st_blocks = 0;
tmpstat_hashfile.st_blksize = 0;
tmpstat_hashfile.st_blocks = 0;
#endif
if (memcmp (&tmpstat_outfile, &tmpstat_hashfile, sizeof (hc_stat_t)) == 0)
if (user_options_extra->hc_workc == 2)
{
event_log_error (hashcat_ctx, "Hashfile and outfile cannot point to the same file.");
char *wlfile = user_options_extra->hc_workv[0];
if (hc_same_files (outfile_ctx->filename, wlfile) == true)
{
event_log_error (hashcat_ctx, "Outfile and wordlist cannot point to the same file.");
return -1;
}
}
}
else if (user_options->attack_mode == ATTACK_MODE_HYBRID2)
{
if (user_options_extra->hc_workc == 2)
{
char *wlfile = user_options_extra->hc_workv[1];
if (hc_same_files (outfile_ctx->filename, wlfile) == true)
{
event_log_error (hashcat_ctx, "Outfile and wordlist cannot point to the same file.");
return -1;
}