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:
parent
9c832092df
commit
5e6d43107e
@ -62,6 +62,7 @@
|
|||||||
- OpenCL Kernels: Vectorized tons of slow kernels to improve CPU cracking speed
|
- 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
|
- 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: 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
|
- WPA cracking: Improved nonce-error-corrections mode to use a both positive and negative corrections
|
||||||
|
|
||||||
##
|
##
|
||||||
|
@ -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);
|
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);
|
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
|
#endif // _SHARED_H
|
||||||
|
87
src/shared.c
87
src/shared.c
@ -462,3 +462,90 @@ char *hc_ctime (const hc_time_t *t, char *buf, MAYBE_UNUSED const size_t buf_siz
|
|||||||
|
|
||||||
return etc;
|
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;
|
||||||
|
}
|
||||||
|
@ -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;
|
event_log_error (hashcat_ctx, "Outfile and hashfile cannot point to the same file.");
|
||||||
|
|
||||||
char *outfile = outfile_ctx->filename;
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
hc_stat_t tmpstat_outfile;
|
// check for outfile vs. cached wordlists
|
||||||
hc_stat_t tmpstat_hashfile;
|
|
||||||
|
|
||||||
memset (&tmpstat_outfile, 0, sizeof (tmpstat_outfile));
|
if (user_options->attack_mode == ATTACK_MODE_STRAIGHT)
|
||||||
memset (&tmpstat_hashfile, 0, sizeof (tmpstat_hashfile));
|
{
|
||||||
|
for (int i = 0; i < user_options_extra->hc_workc; i++)
|
||||||
int do_check = 0;
|
|
||||||
|
|
||||||
FILE *tmp_outfile_fp = fopen (outfile, "r");
|
|
||||||
|
|
||||||
if (tmp_outfile_fp)
|
|
||||||
{
|
{
|
||||||
if (hc_fstat (fileno (tmp_outfile_fp), &tmpstat_outfile))
|
char *wlfile = user_options_extra->hc_workv[i];
|
||||||
|
|
||||||
|
if (hc_same_files (outfile_ctx->filename, wlfile) == true)
|
||||||
{
|
{
|
||||||
fclose (tmp_outfile_fp);
|
event_log_error (hashcat_ctx, "Outfile and wordlist cannot point to the same file.");
|
||||||
|
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (user_options->attack_mode == ATTACK_MODE_COMBI)
|
||||||
|
{
|
||||||
|
if (user_options_extra->hc_workc == 2)
|
||||||
|
{
|
||||||
|
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;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
fclose (tmp_outfile_fp);
|
if (hc_same_files (outfile_ctx->filename, dictfile2) == true)
|
||||||
|
|
||||||
do_check++;
|
|
||||||
}
|
|
||||||
|
|
||||||
FILE *tmp_hashfile_fp = fopen (hashfile, "r");
|
|
||||||
|
|
||||||
if (tmp_hashfile_fp)
|
|
||||||
{
|
|
||||||
if (hc_fstat (fileno (tmp_hashfile_fp), &tmpstat_hashfile))
|
|
||||||
{
|
{
|
||||||
fclose (tmp_hashfile_fp);
|
event_log_error (hashcat_ctx, "Outfile and wordlist cannot point to the same file.");
|
||||||
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
fclose (tmp_hashfile_fp);
|
|
||||||
|
|
||||||
do_check++;
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
if (do_check == 2)
|
else if (user_options->attack_mode == ATTACK_MODE_HYBRID1)
|
||||||
|
{
|
||||||
|
if (user_options_extra->hc_workc == 2)
|
||||||
{
|
{
|
||||||
tmpstat_outfile.st_mode = 0;
|
char *wlfile = user_options_extra->hc_workv[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;
|
if (hc_same_files (outfile_ctx->filename, wlfile) == true)
|
||||||
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)
|
|
||||||
{
|
{
|
||||||
event_log_error (hashcat_ctx, "Hashfile and outfile cannot point to the same file.");
|
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;
|
return -1;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user