2016-09-11 09:42:19 +00:00
/**
2016-09-11 20:20:15 +00:00
* Author . . . . . . : See docs / credits . txt
2016-09-11 09:42:19 +00:00
* License . . . . . : MIT
*/
# include "common.h"
2016-09-14 14:07:24 +00:00
# include "types.h"
# include "memory.h"
2016-10-09 20:41:55 +00:00
# include "event.h"
2017-06-14 12:05:50 +00:00
# include "convert.h"
2016-09-30 09:55:49 +00:00
# include "debugfile.h"
# include "filehandling.h"
# include "hlfmt.h"
2017-11-16 11:37:31 +00:00
# include "terminal.h"
2016-09-23 19:41:05 +00:00
# include "logfile.h"
2016-09-30 09:55:49 +00:00
# include "loopback.h"
2019-04-25 12:45:17 +00:00
# include "backend.h"
2016-09-14 14:07:24 +00:00
# include "outfile.h"
# include "potfile.h"
2016-09-24 09:08:35 +00:00
# include "rp.h"
2016-10-31 10:28:06 +00:00
# include "shared.h"
2016-09-30 09:55:49 +00:00
# include "thread.h"
2016-11-05 10:33:29 +00:00
# include "locking.h"
2019-03-31 15:39:00 +00:00
# include "hashes.h"
2016-09-14 14:07:24 +00:00
2018-10-28 15:47:13 +00:00
# ifdef WITH_BRAIN
# include "brain.h"
# endif
2016-09-30 20:52:44 +00:00
int sort_by_digest_p0p1 ( const void * v1 , const void * v2 , void * v3 )
2016-09-14 17:50:53 +00:00
{
const u32 * d1 = ( const u32 * ) v1 ;
const u32 * d2 = ( const u32 * ) v2 ;
2016-09-30 20:52:44 +00:00
hashconfig_t * hashconfig = ( hashconfig_t * ) v3 ;
2016-10-04 04:35:49 +00:00
const u32 dgst_pos0 = hashconfig - > dgst_pos0 ;
const u32 dgst_pos1 = hashconfig - > dgst_pos1 ;
const u32 dgst_pos2 = hashconfig - > dgst_pos2 ;
const u32 dgst_pos3 = hashconfig - > dgst_pos3 ;
2016-09-14 17:50:53 +00:00
if ( d1 [ dgst_pos3 ] > d2 [ dgst_pos3 ] ) return 1 ;
if ( d1 [ dgst_pos3 ] < d2 [ dgst_pos3 ] ) return - 1 ;
if ( d1 [ dgst_pos2 ] > d2 [ dgst_pos2 ] ) return 1 ;
if ( d1 [ dgst_pos2 ] < d2 [ dgst_pos2 ] ) return - 1 ;
if ( d1 [ dgst_pos1 ] > d2 [ dgst_pos1 ] ) return 1 ;
if ( d1 [ dgst_pos1 ] < d2 [ dgst_pos1 ] ) return - 1 ;
if ( d1 [ dgst_pos0 ] > d2 [ dgst_pos0 ] ) return 1 ;
if ( d1 [ dgst_pos0 ] < d2 [ dgst_pos0 ] ) return - 1 ;
return 0 ;
}
int sort_by_salt ( const void * v1 , const void * v2 )
{
const salt_t * s1 = ( const salt_t * ) v1 ;
const salt_t * s2 = ( const salt_t * ) v2 ;
2020-09-29 13:56:32 +00:00
const int res_pos = ( int ) s1 - > orig_pos - ( int ) s2 - > orig_pos ;
if ( res_pos ! = 0 ) return ( res_pos ) ;
2016-09-30 16:19:42 +00:00
const int res1 = ( int ) s1 - > salt_len - ( int ) s2 - > salt_len ;
2016-09-14 17:50:53 +00:00
if ( res1 ! = 0 ) return ( res1 ) ;
2016-09-30 16:19:42 +00:00
const int res2 = ( int ) s1 - > salt_iter - ( int ) s2 - > salt_iter ;
2016-09-14 17:50:53 +00:00
if ( res2 ! = 0 ) return ( res2 ) ;
2017-06-20 15:17:13 +00:00
for ( int n = 0 ; n < 64 ; n + + )
2016-09-14 17:50:53 +00:00
{
if ( s1 - > salt_buf [ n ] > s2 - > salt_buf [ n ] ) return 1 ;
if ( s1 - > salt_buf [ n ] < s2 - > salt_buf [ n ] ) return - 1 ;
}
2017-06-20 15:17:13 +00:00
for ( int n = 0 ; n < 64 ; n + + )
2016-09-14 17:50:53 +00:00
{
if ( s1 - > salt_buf_pc [ n ] > s2 - > salt_buf_pc [ n ] ) return 1 ;
if ( s1 - > salt_buf_pc [ n ] < s2 - > salt_buf_pc [ n ] ) return - 1 ;
}
return 0 ;
}
2016-09-30 20:52:44 +00:00
int sort_by_hash ( const void * v1 , const void * v2 , void * v3 )
2016-09-14 17:50:53 +00:00
{
const hash_t * h1 = ( const hash_t * ) v1 ;
const hash_t * h2 = ( const hash_t * ) v2 ;
2016-09-30 20:52:44 +00:00
hashconfig_t * hashconfig = ( hashconfig_t * ) v3 ;
2017-09-16 20:33:04 +00:00
if ( hashconfig - > is_salted = = true )
2016-09-14 17:50:53 +00:00
{
const salt_t * s1 = h1 - > salt ;
const salt_t * s2 = h2 - > salt ;
int res = sort_by_salt ( s1 , s2 ) ;
if ( res ! = 0 ) return ( res ) ;
}
const void * d1 = h1 - > digest ;
const void * d2 = h2 - > digest ;
2016-09-30 20:52:44 +00:00
return sort_by_digest_p0p1 ( d1 , d2 , v3 ) ;
2016-09-14 17:50:53 +00:00
}
2016-09-30 20:52:44 +00:00
int sort_by_hash_no_salt ( const void * v1 , const void * v2 , void * v3 )
2016-09-14 17:50:53 +00:00
{
const hash_t * h1 = ( const hash_t * ) v1 ;
const hash_t * h2 = ( const hash_t * ) v2 ;
const void * d1 = h1 - > digest ;
const void * d2 = h2 - > digest ;
2016-09-30 20:52:44 +00:00
return sort_by_digest_p0p1 ( d1 , d2 , v3 ) ;
2016-09-14 17:50:53 +00:00
}
2019-03-31 15:39:00 +00:00
int hash_encode ( const hashconfig_t * hashconfig , const hashes_t * hashes , const module_ctx_t * module_ctx , char * out_buf , const int out_size , const u32 salt_pos , const u32 digest_pos )
{
if ( module_ctx - > module_hash_encode = = MODULE_DEFAULT )
{
return snprintf ( out_buf , out_size , " %s " , hashes - > hashfile ) ;
}
salt_t * salts_buf = hashes - > salts_buf ;
salts_buf + = salt_pos ;
2019-03-31 18:17:17 +00:00
const u32 digest_cur = salts_buf - > digests_offset + digest_pos ;
2019-03-31 15:39:00 +00:00
void * digests_buf = hashes - > digests_buf ;
void * esalts_buf = hashes - > esalts_buf ;
void * hook_salts_buf = hashes - > hook_salts_buf ;
hashinfo_t * * hash_info = hashes - > hash_info ;
char * digests_buf_ptr = ( char * ) digests_buf ;
char * esalts_buf_ptr = ( char * ) esalts_buf ;
char * hook_salts_buf_ptr = ( char * ) hook_salts_buf ;
hashinfo_t * hash_info_ptr = NULL ;
digests_buf_ptr + = digest_cur * hashconfig - > dgst_size ;
esalts_buf_ptr + = digest_cur * hashconfig - > esalt_size ;
hook_salts_buf_ptr + = digest_cur * hashconfig - > hook_salt_size ;
if ( hash_info ) hash_info_ptr = hash_info [ digest_cur ] ;
const int out_len = module_ctx - > module_hash_encode
(
hashconfig ,
digests_buf_ptr ,
salts_buf ,
esalts_buf_ptr ,
hook_salts_buf_ptr ,
hash_info_ptr ,
out_buf ,
out_size
) ;
return out_len ;
}
2016-10-09 20:41:55 +00:00
int save_hash ( hashcat_ctx_t * hashcat_ctx )
2016-10-04 14:18:49 +00:00
{
2016-10-06 08:55:14 +00:00
hashes_t * hashes = hashcat_ctx - > hashes ;
hashconfig_t * hashconfig = hashcat_ctx - > hashconfig ;
2019-01-07 09:05:50 +00:00
module_ctx_t * module_ctx = hashcat_ctx - > module_ctx ;
2016-10-06 08:55:14 +00:00
user_options_t * user_options = hashcat_ctx - > user_options ;
2017-04-10 20:35:01 +00:00
const char * hashfile = hashes - > hashfile ;
2016-10-04 14:18:49 +00:00
2017-10-03 05:10:10 +00:00
char * new_hashfile ;
char * old_hashfile ;
2016-10-04 14:18:49 +00:00
2017-10-03 05:10:10 +00:00
hc_asprintf ( & new_hashfile , " %s.new " , hashfile ) ;
hc_asprintf ( & old_hashfile , " %s.old " , hashfile ) ;
2016-10-04 14:18:49 +00:00
unlink ( new_hashfile ) ;
char separator = hashconfig - > separator ;
2019-06-26 17:06:46 +00:00
HCFILE fp ;
2016-10-04 14:18:49 +00:00
2019-07-01 15:27:08 +00:00
if ( hc_fopen ( & fp , new_hashfile , " wb " ) = = false )
2016-10-04 14:18:49 +00:00
{
2017-02-04 01:53:50 +00:00
event_log_error ( hashcat_ctx , " %s: %s " , new_hashfile , strerror ( errno ) ) ;
2016-10-04 14:18:49 +00:00
2020-05-14 17:21:59 +00:00
hcfree ( new_hashfile ) ;
hcfree ( old_hashfile ) ;
2017-10-04 11:04:58 +00:00
2016-10-09 20:41:55 +00:00
return - 1 ;
2016-10-04 14:18:49 +00:00
}
2019-06-30 23:30:24 +00:00
if ( hc_lockfile ( & fp ) = = - 1 )
2016-11-05 10:33:29 +00:00
{
2019-06-26 17:06:46 +00:00
hc_fclose ( & fp ) ;
2016-11-20 22:15:54 +00:00
2017-02-04 01:53:50 +00:00
event_log_error ( hashcat_ctx , " %s: %s " , new_hashfile , strerror ( errno ) ) ;
2016-11-05 10:33:29 +00:00
2020-05-14 17:21:59 +00:00
hcfree ( new_hashfile ) ;
hcfree ( old_hashfile ) ;
2017-10-04 11:04:58 +00:00
2016-11-05 10:33:29 +00:00
return - 1 ;
}
2016-11-20 21:54:52 +00:00
u8 * out_buf = ( u8 * ) hcmalloc ( HCBUFSIZ_LARGE ) ;
2016-11-19 23:03:29 +00:00
2016-10-04 14:18:49 +00:00
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 + + )
{
2019-01-07 09:05:50 +00:00
const u32 idx = salt_buf - > digests_offset + digest_pos ;
2016-10-04 14:18:49 +00:00
if ( hashes - > digests_shown [ idx ] = = 1 ) continue ;
2019-01-08 14:55:11 +00:00
if ( module_ctx - > module_hash_binary_save ! = MODULE_DEFAULT )
2016-10-26 22:32:38 +00:00
{
2019-01-07 09:05:50 +00:00
char * binary_buf = NULL ;
2016-10-26 22:32:38 +00:00
2019-01-08 14:55:11 +00:00
const int binary_len = module_ctx - > module_hash_binary_save ( hashes , salt_pos , digest_pos , & binary_buf ) ;
2016-10-26 22:32:38 +00:00
2019-06-27 18:18:47 +00:00
hc_fwrite ( binary_buf , binary_len , 1 , & fp ) ;
2019-01-19 19:09:32 +00:00
hcfree ( binary_buf ) ;
2016-10-26 22:32:38 +00:00
}
else
2016-10-04 14:18:49 +00:00
{
2016-10-19 10:42:41 +00:00
if ( user_options - > username = = true )
2016-10-04 14:18:49 +00:00
{
user_t * user = hashes - > hash_info [ idx ] - > user ;
u32 i ;
2019-06-26 17:06:46 +00:00
for ( i = 0 ; i < user - > user_len ; i + + ) hc_fputc ( user - > user_name [ i ] , & fp ) ;
2016-10-04 14:18:49 +00:00
2019-06-26 17:06:46 +00:00
hc_fputc ( separator , & fp ) ;
2016-10-04 14:18:49 +00:00
}
2019-03-31 15:39:00 +00:00
const int out_len = hash_encode ( hashcat_ctx - > hashconfig , hashcat_ctx - > hashes , hashcat_ctx - > module_ctx , ( char * ) out_buf , HCBUFSIZ_LARGE , salt_pos , digest_pos ) ;
2016-10-04 14:18:49 +00:00
2019-01-11 22:11:56 +00:00
out_buf [ out_len ] = 0 ;
2016-10-04 14:18:49 +00:00
2019-06-26 17:06:46 +00:00
hc_fprintf ( & fp , " %s " EOL , out_buf ) ;
2016-10-04 14:18:49 +00:00
}
}
}
2016-11-19 23:03:29 +00:00
hcfree ( out_buf ) ;
2019-06-26 17:06:46 +00:00
hc_fflush ( & fp ) ;
2016-10-04 14:18:49 +00:00
2020-02-29 09:40:47 +00:00
if ( hc_unlockfile ( & fp ) = = - 1 )
{
hc_fclose ( & fp ) ;
event_log_error ( hashcat_ctx , " %s: %s " , new_hashfile , strerror ( errno ) ) ;
2020-05-14 17:21:59 +00:00
hcfree ( new_hashfile ) ;
hcfree ( old_hashfile ) ;
2020-02-29 09:40:47 +00:00
return - 1 ;
}
2019-06-26 17:06:46 +00:00
hc_fclose ( & fp ) ;
2016-10-04 14:18:49 +00:00
unlink ( old_hashfile ) ;
if ( rename ( hashfile , old_hashfile ) ! = 0 )
{
2017-02-04 01:53:50 +00:00
event_log_error ( hashcat_ctx , " Rename file '%s' to '%s': %s " , hashfile , old_hashfile , strerror ( errno ) ) ;
2016-10-04 14:18:49 +00:00
2020-05-14 17:21:59 +00:00
hcfree ( new_hashfile ) ;
hcfree ( old_hashfile ) ;
2017-10-04 11:04:58 +00:00
2016-10-09 20:41:55 +00:00
return - 1 ;
2016-10-04 14:18:49 +00:00
}
unlink ( hashfile ) ;
if ( rename ( new_hashfile , hashfile ) ! = 0 )
{
2017-02-04 01:53:50 +00:00
event_log_error ( hashcat_ctx , " Rename file '%s' to '%s': %s " , new_hashfile , hashfile , strerror ( errno ) ) ;
2016-10-04 14:18:49 +00:00
2020-05-14 17:21:59 +00:00
hcfree ( new_hashfile ) ;
hcfree ( old_hashfile ) ;
2017-10-04 11:04:58 +00:00
2016-10-09 20:41:55 +00:00
return - 1 ;
2016-10-04 14:18:49 +00:00
}
unlink ( old_hashfile ) ;
2016-10-09 20:41:55 +00:00
2020-05-14 17:21:59 +00:00
hcfree ( new_hashfile ) ;
hcfree ( old_hashfile ) ;
2017-10-04 11:04:58 +00:00
2016-10-09 20:41:55 +00:00
return 0 ;
2016-10-04 14:18:49 +00:00
}
2021-07-27 11:36:48 +00:00
int check_hash ( hashcat_ctx_t * hashcat_ctx , hc_device_param_t * device_param , plain_t * plain )
2016-10-04 14:18:49 +00:00
{
2019-01-03 14:43:19 +00:00
const debugfile_ctx_t * debugfile_ctx = hashcat_ctx - > debugfile_ctx ;
const hashes_t * hashes = hashcat_ctx - > hashes ;
const hashconfig_t * hashconfig = hashcat_ctx - > hashconfig ;
const loopback_ctx_t * loopback_ctx = hashcat_ctx - > loopback_ctx ;
const module_ctx_t * module_ctx = hashcat_ctx - > module_ctx ;
2016-10-04 14:18:49 +00:00
const u32 salt_pos = plain - > salt_pos ;
const u32 digest_pos = plain - > digest_pos ; // relative
2019-03-30 15:32:11 +00:00
void * tmps = NULL ;
2021-07-26 17:57:24 +00:00
cl_event opencl_event ;
2021-08-04 18:49:22 +00:00
int rc = - 1 ;
2021-07-26 17:57:24 +00:00
2019-03-30 15:32:11 +00:00
if ( hashconfig - > opts_type & OPTS_TYPE_COPY_TMPS )
{
2019-03-30 15:55:55 +00:00
tmps = hcmalloc ( hashconfig - > tmp_size ) ;
2019-03-30 15:32:11 +00:00
2019-05-05 09:57:54 +00:00
if ( device_param - > is_cuda = = true )
{
2021-07-27 11:36:48 +00:00
rc = hc_cuMemcpyDtoHAsync ( hashcat_ctx , tmps , device_param - > cuda_d_tmps + ( plain - > gidvid * hashconfig - > tmp_size ) , hashconfig - > tmp_size , device_param - > cuda_stream ) ;
2021-07-27 09:57:26 +00:00
2021-07-27 11:36:48 +00:00
if ( rc = = 0 )
{
rc = hc_cuEventRecord ( hashcat_ctx , device_param - > cuda_event3 , device_param - > cuda_stream ) ;
}
if ( rc = = - 1 )
{
2021-08-01 11:21:18 +00:00
hcfree ( tmps ) ;
2021-07-27 11:36:48 +00:00
return - 1 ;
}
2019-05-05 09:57:54 +00:00
}
2021-07-11 10:38:59 +00:00
if ( device_param - > is_hip = = true )
{
2021-07-27 11:36:48 +00:00
rc = hc_hipMemcpyDtoHAsync ( hashcat_ctx , tmps , device_param - > hip_d_tmps + ( plain - > gidvid * hashconfig - > tmp_size ) , hashconfig - > tmp_size , device_param - > hip_stream ) ;
2021-07-27 09:57:26 +00:00
2021-07-27 11:36:48 +00:00
if ( rc = = 0 )
{
rc = hc_hipEventRecord ( hashcat_ctx , device_param - > hip_event3 , device_param - > hip_stream ) ;
}
if ( rc = = - 1 )
{
2021-08-01 11:21:18 +00:00
hcfree ( tmps ) ;
2021-07-27 11:36:48 +00:00
return - 1 ;
}
2021-07-11 10:38:59 +00:00
}
2022-02-05 21:48:16 +00:00
# if defined (__APPLE__)
if ( device_param - > is_metal = = true )
{
rc = hc_mtlMemcpyDtoH ( hashcat_ctx , device_param - > metal_command_queue , tmps , device_param - > metal_d_tmps , plain - > gidvid * hashconfig - > tmp_size , hashconfig - > tmp_size ) ;
if ( rc = = - 1 )
{
hcfree ( tmps ) ;
return - 1 ;
}
}
# endif
2019-05-05 09:57:54 +00:00
if ( device_param - > is_opencl = = true )
{
2021-07-27 11:36:48 +00:00
rc = hc_clEnqueueReadBuffer ( hashcat_ctx , device_param - > opencl_command_queue , device_param - > opencl_d_tmps , CL_FALSE , plain - > gidvid * hashconfig - > tmp_size , hashconfig - > tmp_size , tmps , 0 , NULL , & opencl_event ) ;
2021-07-27 09:57:26 +00:00
2021-07-27 11:36:48 +00:00
if ( rc = = 0 )
{
rc = hc_clFlush ( hashcat_ctx , device_param - > opencl_command_queue ) ;
}
if ( rc = = - 1 )
{
2021-08-01 11:21:18 +00:00
hcfree ( tmps ) ;
2021-07-27 11:36:48 +00:00
return - 1 ;
}
2019-05-05 09:57:54 +00:00
}
2019-03-30 15:32:11 +00:00
}
2016-10-04 14:18:49 +00:00
// hash
2016-10-30 21:22:26 +00:00
u8 * out_buf = hashes - > out_buf ;
2016-10-19 11:51:06 +00:00
2021-07-27 11:36:48 +00:00
int out_len = hash_encode ( hashconfig , hashes , module_ctx , ( char * ) out_buf , HCBUFSIZ_LARGE , salt_pos , digest_pos ) ;
2016-10-04 14:18:49 +00:00
2019-01-11 22:11:56 +00:00
out_buf [ out_len ] = 0 ;
2016-10-04 14:18:49 +00:00
// plain
2021-07-26 17:57:24 +00:00
u8 plain_buf [ HCBUFSIZ_TINY ] = { 0 } ; // while the password itself can have only length 256, the module could encode it with something like base64 which inflates the requires buffer size
2021-07-26 19:25:50 +00:00
u8 postprocess_buf [ HCBUFSIZ_TINY ] = { 0 } ;
2019-07-11 15:56:34 +00:00
u8 * plain_ptr = plain_buf ;
2020-01-13 13:40:52 +00:00
2016-10-04 14:18:49 +00:00
int plain_len = 0 ;
2020-01-13 13:40:52 +00:00
build_plain ( hashcat_ctx , device_param , plain , ( u32 * ) plain_buf , & plain_len ) ;
2016-10-04 14:18:49 +00:00
2019-01-05 19:17:12 +00:00
if ( module_ctx - > module_build_plain_postprocess ! = MODULE_DEFAULT )
2018-10-02 15:01:54 +00:00
{
2021-07-26 17:57:24 +00:00
if ( hashconfig - > opts_type & OPTS_TYPE_COPY_TMPS )
{
if ( device_param - > is_cuda = = true )
{
2021-07-27 11:36:48 +00:00
if ( hc_cuEventSynchronize ( hashcat_ctx , device_param - > cuda_event3 ) = = - 1 ) return - 1 ;
2021-07-26 17:57:24 +00:00
}
if ( device_param - > is_hip = = true )
{
2021-07-27 11:36:48 +00:00
if ( hc_hipEventSynchronize ( hashcat_ctx , device_param - > hip_event3 ) = = - 1 ) return - 1 ;
2021-07-26 17:57:24 +00:00
}
if ( device_param - > is_opencl = = true )
{
2021-07-27 11:36:48 +00:00
if ( hc_clWaitForEvents ( hashcat_ctx , 1 , & opencl_event ) = = - 1 ) return - 1 ;
2021-07-26 17:57:24 +00:00
}
}
2018-10-02 15:01:54 +00:00
2021-07-27 11:36:48 +00:00
plain_len = module_ctx - > module_build_plain_postprocess ( hashconfig , hashes , tmps , ( u32 * ) plain_buf , sizeof ( plain_buf ) , plain_len , ( u32 * ) postprocess_buf , sizeof ( postprocess_buf ) ) ;
2019-01-03 14:43:19 +00:00
2021-07-26 19:25:50 +00:00
plain_ptr = postprocess_buf ;
2018-10-02 15:01:54 +00:00
}
2016-10-04 14:18:49 +00:00
// crackpos
u64 crackpos = 0 ;
build_crackpos ( hashcat_ctx , device_param , plain , & crackpos ) ;
// debug
2017-08-11 09:15:43 +00:00
u8 debug_rule_buf [ RP_PASSWORD_SIZE ] = { 0 } ;
2016-10-04 14:18:49 +00:00
int debug_rule_len = 0 ; // -1 error
2017-08-11 09:15:43 +00:00
u8 debug_plain_ptr [ RP_PASSWORD_SIZE ] = { 0 } ;
2016-10-04 14:18:49 +00:00
int debug_plain_len = 0 ;
build_debugdata ( hashcat_ctx , device_param , plain , debug_rule_buf , & debug_rule_len , debug_plain_ptr , & debug_plain_len ) ;
2016-09-14 14:07:24 +00:00
// outfile, can be either to file or stdout
// if an error occurs opening the file, send to stdout as fallback
// the fp gets opened for each cracked hash so that the user can modify (move) the outfile while hashcat runs
2016-10-06 13:40:27 +00:00
outfile_write_open ( hashcat_ctx ) ;
2016-09-14 14:07:24 +00:00
2016-10-30 21:56:45 +00:00
u8 * tmp_buf = hashes - > tmp_buf ;
2016-10-12 09:27:10 +00:00
2016-10-30 21:47:48 +00:00
tmp_buf [ 0 ] = 0 ;
2020-06-15 13:43:49 +00:00
const int tmp_len = outfile_write ( hashcat_ctx , ( char * ) out_buf , out_len , plain_ptr , plain_len , crackpos , NULL , 0 , true , ( char * ) tmp_buf ) ;
2016-09-14 14:07:24 +00:00
2016-10-12 09:27:10 +00:00
EVENT_DATA ( EVENT_CRACKER_HASH_CRACKED , tmp_buf , tmp_len ) ;
2019-07-11 11:04:18 +00:00
outfile_write_close ( hashcat_ctx ) ;
2019-04-01 10:32:11 +00:00
// potfile
// we can have either used-defined hooks or reuse the same format as input format
// no need for locking, we're in a mutex protected function
if ( module_ctx - > module_hash_encode_potfile ! = MODULE_DEFAULT )
{
2021-07-26 17:57:24 +00:00
if ( hashconfig - > opts_type & OPTS_TYPE_COPY_TMPS )
{
if ( device_param - > is_cuda = = true )
{
2021-07-27 11:36:48 +00:00
if ( hc_cuEventSynchronize ( hashcat_ctx , device_param - > cuda_event3 ) = = - 1 ) return - 1 ;
2021-07-26 17:57:24 +00:00
}
if ( device_param - > is_hip = = true )
{
2021-07-27 11:36:48 +00:00
if ( hc_hipEventSynchronize ( hashcat_ctx , device_param - > hip_event3 ) = = - 1 ) return - 1 ;
2021-07-26 17:57:24 +00:00
}
if ( device_param - > is_opencl = = true )
{
2021-07-27 11:36:48 +00:00
if ( hc_clWaitForEvents ( hashcat_ctx , 1 , & opencl_event ) = = - 1 ) return - 1 ;
2021-07-26 17:57:24 +00:00
}
}
2019-04-01 10:32:11 +00:00
salt_t * salts_buf = hashes - > salts_buf ;
salts_buf + = salt_pos ;
const u32 digest_cur = salts_buf - > digests_offset + digest_pos ;
void * digests_buf = hashes - > digests_buf ;
void * esalts_buf = hashes - > esalts_buf ;
void * hook_salts_buf = hashes - > hook_salts_buf ;
hashinfo_t * * hash_info = hashes - > hash_info ;
char * digests_buf_ptr = ( char * ) digests_buf ;
char * esalts_buf_ptr = ( char * ) esalts_buf ;
char * hook_salts_buf_ptr = ( char * ) hook_salts_buf ;
hashinfo_t * hash_info_ptr = NULL ;
digests_buf_ptr + = digest_cur * hashconfig - > dgst_size ;
esalts_buf_ptr + = digest_cur * hashconfig - > esalt_size ;
hook_salts_buf_ptr + = digest_cur * hashconfig - > hook_salt_size ;
if ( hash_info ) hash_info_ptr = hash_info [ digest_cur ] ;
out_len = module_ctx - > module_hash_encode_potfile
(
hashconfig ,
digests_buf_ptr ,
salts_buf ,
esalts_buf_ptr ,
hook_salts_buf_ptr ,
hash_info_ptr ,
( char * ) out_buf ,
HCBUFSIZ_LARGE ,
tmps
) ;
out_buf [ out_len ] = 0 ;
}
potfile_write_append ( hashcat_ctx , ( char * ) out_buf , out_len , plain_ptr , plain_len ) ;
2016-09-14 14:07:24 +00:00
// if enabled, update also the loopback file
2019-07-02 19:30:35 +00:00
if ( loopback_ctx - > fp . pfp ! = NULL )
2016-09-14 14:07:24 +00:00
{
2016-10-06 15:01:29 +00:00
loopback_write_append ( hashcat_ctx , plain_ptr , plain_len ) ;
2016-09-14 14:07:24 +00:00
}
// if enabled, update also the (rule) debug file
2019-07-02 19:30:35 +00:00
if ( debugfile_ctx - > fp . pfp ! = NULL )
2016-09-14 14:07:24 +00:00
{
// the next check implies that:
2016-09-22 13:41:59 +00:00
// - (user_options->attack_mode == ATTACK_MODE_STRAIGHT)
2016-09-14 14:07:24 +00:00
// - debug_mode > 0
if ( ( debug_plain_len > 0 ) | | ( debug_rule_len > 0 ) )
{
2016-11-14 19:29:25 +00:00
debugfile_write_append ( hashcat_ctx , debug_rule_buf , debug_rule_len , plain_ptr , plain_len , debug_plain_ptr , debug_plain_len ) ;
2016-09-14 14:07:24 +00:00
}
}
2019-03-30 15:32:11 +00:00
if ( hashconfig - > opts_type & OPTS_TYPE_COPY_TMPS )
{
2021-07-27 11:36:48 +00:00
hcfree ( tmps ) ;
2021-07-26 17:57:24 +00:00
if ( device_param - > is_opencl = = true )
{
2021-07-27 11:36:48 +00:00
if ( hc_clReleaseEvent ( hashcat_ctx , opencl_event ) = = - 1 ) return - 1 ;
2021-07-26 17:57:24 +00:00
}
2019-03-30 15:32:11 +00:00
}
2021-07-27 11:36:48 +00:00
return 0 ;
2016-09-14 14:07:24 +00:00
}
2020-09-29 13:56:32 +00:00
//int check_cracked (hashcat_ctx_t *hashcat_ctx, hc_device_param_t *device_param, const u32 salt_pos)
int check_cracked ( hashcat_ctx_t * hashcat_ctx , hc_device_param_t * device_param )
2016-09-14 14:07:24 +00:00
{
2018-02-10 19:44:13 +00:00
cpt_ctx_t * cpt_ctx = hashcat_ctx - > cpt_ctx ;
hashconfig_t * hashconfig = hashcat_ctx - > hashconfig ;
hashes_t * hashes = hashcat_ctx - > hashes ;
status_ctx_t * status_ctx = hashcat_ctx - > status_ctx ;
user_options_t * user_options = hashcat_ctx - > user_options ;
2016-09-30 20:52:44 +00:00
2019-11-26 09:55:57 +00:00
u32 num_cracked = 0 ;
2021-08-04 18:49:22 +00:00
int rc = - 1 ;
2016-09-14 14:07:24 +00:00
2019-05-05 09:57:54 +00:00
if ( device_param - > is_cuda = = true )
{
2021-07-26 17:57:24 +00:00
if ( hc_cuMemcpyDtoHAsync ( hashcat_ctx , & num_cracked , device_param - > cuda_d_result , sizeof ( u32 ) , device_param - > cuda_stream ) = = - 1 ) return - 1 ;
2019-05-05 09:57:54 +00:00
2021-07-26 17:57:24 +00:00
if ( hc_cuStreamSynchronize ( hashcat_ctx , device_param - > cuda_stream ) = = - 1 ) return - 1 ;
2019-05-05 09:57:54 +00:00
}
2016-09-14 14:07:24 +00:00
2021-07-11 10:38:59 +00:00
if ( device_param - > is_hip = = true )
{
2021-07-26 17:57:24 +00:00
if ( hc_hipMemcpyDtoHAsync ( hashcat_ctx , & num_cracked , device_param - > hip_d_result , sizeof ( u32 ) , device_param - > hip_stream ) = = - 1 ) return - 1 ;
2021-07-11 10:38:59 +00:00
2021-07-26 17:57:24 +00:00
if ( hc_hipStreamSynchronize ( hashcat_ctx , device_param - > hip_stream ) = = - 1 ) return - 1 ;
2021-07-11 10:38:59 +00:00
}
2022-02-05 21:48:16 +00:00
# if defined (__APPLE__)
if ( device_param - > is_metal = = true )
{
if ( hc_mtlMemcpyDtoH ( hashcat_ctx , device_param - > metal_command_queue , & num_cracked , device_param - > metal_d_result , 0 , sizeof ( u32 ) ) = = - 1 ) return - 1 ;
}
# endif
2019-05-05 09:57:54 +00:00
if ( device_param - > is_opencl = = true )
2016-09-14 14:07:24 +00:00
{
2021-07-28 21:07:10 +00:00
/* blocking */
2021-07-26 17:57:24 +00:00
if ( hc_clEnqueueReadBuffer ( hashcat_ctx , device_param - > opencl_command_queue , device_param - > opencl_d_result , CL_TRUE , 0 , sizeof ( u32 ) , & num_cracked , 0 , NULL , NULL ) = = - 1 ) return - 1 ;
2016-09-14 14:07:24 +00:00
}
2021-07-26 17:57:24 +00:00
if ( num_cracked = = 0 | | user_options - > speed_only = = true )
2018-02-10 19:44:13 +00:00
{
2021-07-30 09:24:21 +00:00
// we want to get the num_cracked in benchmark mode because it has an influence in performance
2018-02-11 09:56:08 +00:00
// however if the benchmark cracks the artificial hash used for benchmarks we don't want to see that!
2018-02-10 19:44:13 +00:00
return 0 ;
}
2021-07-30 09:24:21 +00:00
plain_t * cracked = ( plain_t * ) hcmalloc ( num_cracked * sizeof ( plain_t ) ) ;
2019-05-05 09:57:54 +00:00
2021-07-26 17:57:24 +00:00
if ( device_param - > is_cuda = = true )
{
2021-07-27 13:28:07 +00:00
rc = hc_cuMemcpyDtoHAsync ( hashcat_ctx , cracked , device_param - > cuda_d_plain_bufs , num_cracked * sizeof ( plain_t ) , device_param - > cuda_stream ) ;
2016-09-14 14:07:24 +00:00
2021-07-27 13:28:07 +00:00
if ( rc = = 0 )
{
rc = hc_cuStreamSynchronize ( hashcat_ctx , device_param - > cuda_stream ) ;
}
if ( rc = = - 1 )
{
hcfree ( cracked ) ;
return - 1 ;
}
2021-07-26 17:57:24 +00:00
}
2021-07-11 10:38:59 +00:00
2021-07-26 17:57:24 +00:00
if ( device_param - > is_hip = = true )
{
2021-07-27 13:28:07 +00:00
rc = hc_hipMemcpyDtoHAsync ( hashcat_ctx , cracked , device_param - > hip_d_plain_bufs , num_cracked * sizeof ( plain_t ) , device_param - > hip_stream ) ;
2021-07-11 10:38:59 +00:00
2021-07-27 13:28:07 +00:00
if ( rc = = 0 )
{
rc = hc_hipStreamSynchronize ( hashcat_ctx , device_param - > hip_stream ) ;
}
if ( rc = = - 1 )
{
hcfree ( cracked ) ;
return - 1 ;
}
2021-07-26 17:57:24 +00:00
}
2016-09-14 14:07:24 +00:00
2022-02-05 21:48:16 +00:00
# if defined (__APPLE__)
if ( device_param - > is_metal = = true )
{
rc = hc_mtlMemcpyDtoH ( hashcat_ctx , device_param - > metal_command_queue , cracked , device_param - > metal_d_plain_bufs , 0 , num_cracked * sizeof ( plain_t ) ) ;
if ( rc = = - 1 )
{
hcfree ( cracked ) ;
return - 1 ;
}
}
# endif
2021-07-26 17:57:24 +00:00
if ( device_param - > is_opencl = = true )
{
2021-07-28 21:07:10 +00:00
/* blocking */
2021-07-27 13:28:07 +00:00
rc = hc_clEnqueueReadBuffer ( hashcat_ctx , device_param - > opencl_command_queue , device_param - > opencl_d_plain_bufs , CL_TRUE , 0 , num_cracked * sizeof ( plain_t ) , cracked , 0 , NULL , NULL ) ;
if ( rc = = - 1 )
{
hcfree ( cracked ) ;
return - 1 ;
}
2021-07-26 17:57:24 +00:00
}
2016-09-14 14:07:24 +00:00
2021-07-26 17:57:24 +00:00
u32 cpt_cracked = 0 ;
2016-09-14 14:07:24 +00:00
2021-07-26 17:57:24 +00:00
hc_thread_mutex_lock ( status_ctx - > mux_display ) ;
2016-09-14 14:07:24 +00:00
2021-07-26 17:57:24 +00:00
for ( u32 i = 0 ; i < num_cracked ; i + + )
{
const u32 hash_pos = cracked [ i ] . hash_pos ;
2016-09-14 14:07:24 +00:00
2021-07-26 17:57:24 +00:00
if ( hashes - > digests_shown [ hash_pos ] = = 1 ) continue ;
2016-09-14 14:07:24 +00:00
2021-07-26 17:57:24 +00:00
const u32 salt_pos = cracked [ i ] . salt_pos ;
salt_t * salt_buf = & hashes - > salts_buf [ salt_pos ] ;
2020-12-16 16:48:53 +00:00
2021-07-26 17:57:24 +00:00
if ( ( hashconfig - > opts_type & OPTS_TYPE_PT_NEVERCRACK ) = = 0 )
{
hashes - > digests_shown [ hash_pos ] = 1 ;
2016-09-14 14:07:24 +00:00
2021-07-26 17:57:24 +00:00
hashes - > digests_done + + ;
2016-09-14 14:07:24 +00:00
2022-08-19 10:02:21 +00:00
hashes - > digests_done_new + + ;
2021-07-26 17:57:24 +00:00
cpt_cracked + + ;
2016-09-14 14:07:24 +00:00
2021-07-26 17:57:24 +00:00
salt_buf - > digests_done + + ;
2016-09-14 14:07:24 +00:00
2021-07-26 17:57:24 +00:00
if ( salt_buf - > digests_done = = salt_buf - > digests_cnt )
{
hashes - > salts_shown [ salt_pos ] = 1 ;
2016-09-14 14:07:24 +00:00
2021-07-26 17:57:24 +00:00
hashes - > salts_done + + ;
2020-12-16 16:48:53 +00:00
}
2021-07-26 17:57:24 +00:00
}
2020-09-29 13:56:32 +00:00
2021-07-26 17:57:24 +00:00
if ( hashes - > salts_done = = hashes - > salts_cnt ) mycracked ( hashcat_ctx ) ;
2020-09-29 13:56:32 +00:00
2021-07-27 13:28:07 +00:00
rc = check_hash ( hashcat_ctx , device_param , & cracked [ i ] ) ;
if ( rc = = - 1 )
{
break ;
}
2020-09-29 13:56:32 +00:00
2021-07-26 17:57:24 +00:00
if ( hashconfig - > opts_type & OPTS_TYPE_PT_NEVERCRACK )
{
// we need to reset cracked state on the device
// otherwise host thinks again and again the hash was cracked
// and returns invalid password each time
2020-09-29 13:56:32 +00:00
2021-07-26 17:57:24 +00:00
if ( device_param - > is_cuda = = true )
{
2021-07-27 16:01:13 +00:00
rc = run_cuda_kernel_bzero ( hashcat_ctx , device_param , device_param - > cuda_d_digests_shown + ( salt_buf - > digests_offset * sizeof ( u32 ) ) , salt_buf - > digests_cnt * sizeof ( u32 ) ) ;
2021-07-27 13:28:07 +00:00
if ( rc = = - 1 )
{
break ;
}
2021-07-26 17:57:24 +00:00
}
2021-07-11 10:38:59 +00:00
2021-07-26 17:57:24 +00:00
if ( device_param - > is_hip = = true )
{
2021-07-27 16:01:13 +00:00
rc = run_hip_kernel_bzero ( hashcat_ctx , device_param , device_param - > hip_d_digests_shown + ( salt_buf - > digests_offset * sizeof ( u32 ) ) , salt_buf - > digests_cnt * sizeof ( u32 ) ) ;
2021-07-27 13:28:07 +00:00
if ( rc = = - 1 )
{
break ;
}
2021-07-26 17:57:24 +00:00
}
2020-09-29 13:56:32 +00:00
2022-02-05 21:48:16 +00:00
# if defined (__APPLE__)
if ( device_param - > is_metal = = true )
{
rc = run_metal_kernel_memset32 ( hashcat_ctx , device_param , device_param - > metal_d_digests_shown , salt_buf - > digests_offset * sizeof ( u32 ) , 0 , salt_buf - > digests_cnt * sizeof ( u32 ) ) ;
if ( rc = = - 1 )
{
break ;
}
}
# endif
2021-07-26 17:57:24 +00:00
if ( device_param - > is_opencl = = true )
{
2021-07-27 16:01:13 +00:00
/* NOTE: run_opencl_kernel_bzero() does not handle buffer offset */
2021-08-01 12:19:15 +00:00
rc = run_opencl_kernel_memset32 ( hashcat_ctx , device_param , device_param - > opencl_d_digests_shown , salt_buf - > digests_offset * sizeof ( u32 ) , 0 , salt_buf - > digests_cnt * sizeof ( u32 ) ) ;
2021-07-27 13:28:07 +00:00
if ( rc = = - 1 )
{
break ;
}
2016-09-14 14:07:24 +00:00
}
}
2021-07-26 17:57:24 +00:00
}
2016-09-14 14:07:24 +00:00
2021-07-26 17:57:24 +00:00
hc_thread_mutex_unlock ( status_ctx - > mux_display ) ;
2016-09-14 14:07:24 +00:00
2021-07-26 17:57:24 +00:00
hcfree ( cracked ) ;
2016-09-14 14:07:24 +00:00
2021-07-27 13:28:07 +00:00
if ( rc = = - 1 )
{
return - 1 ;
}
2021-07-26 17:57:24 +00:00
if ( cpt_cracked > 0 )
{
hc_thread_mutex_lock ( status_ctx - > mux_display ) ;
2016-09-14 14:07:24 +00:00
2021-07-26 17:57:24 +00:00
cpt_ctx - > cpt_buf [ cpt_ctx - > cpt_pos ] . timestamp = time ( NULL ) ;
cpt_ctx - > cpt_buf [ cpt_ctx - > cpt_pos ] . cracked = cpt_cracked ;
2016-09-14 14:07:24 +00:00
2021-07-26 17:57:24 +00:00
cpt_ctx - > cpt_pos + + ;
2016-09-14 14:07:24 +00:00
2021-07-26 17:57:24 +00:00
cpt_ctx - > cpt_total + = cpt_cracked ;
2016-09-14 14:07:24 +00:00
2021-07-26 17:57:24 +00:00
if ( cpt_ctx - > cpt_pos = = CPT_CACHE ) cpt_ctx - > cpt_pos = 0 ;
2016-09-14 14:07:24 +00:00
2021-07-26 17:57:24 +00:00
hc_thread_mutex_unlock ( status_ctx - > mux_display ) ;
}
2016-09-14 14:07:24 +00:00
2021-07-26 17:57:24 +00:00
if ( device_param - > is_cuda = = true )
{
2021-07-27 09:57:26 +00:00
if ( run_cuda_kernel_bzero ( hashcat_ctx , device_param , device_param - > cuda_d_result , sizeof ( u32 ) ) = = - 1 ) return - 1 ;
2021-07-26 17:57:24 +00:00
}
2021-07-11 10:38:59 +00:00
2021-07-26 17:57:24 +00:00
if ( device_param - > is_hip = = true )
{
2021-07-27 09:57:26 +00:00
if ( run_hip_kernel_bzero ( hashcat_ctx , device_param , device_param - > hip_d_result , sizeof ( u32 ) ) = = - 1 ) return - 1 ;
2021-07-26 17:57:24 +00:00
}
2016-09-14 14:07:24 +00:00
2022-02-05 21:48:16 +00:00
# if defined (__APPLE__)
if ( device_param - > is_metal = = true )
{
if ( run_metal_kernel_bzero ( hashcat_ctx , device_param , device_param - > metal_d_result , sizeof ( u32 ) ) = = - 1 ) return - 1 ;
}
# endif
2021-07-26 17:57:24 +00:00
if ( device_param - > is_opencl = = true )
{
2021-07-27 09:57:26 +00:00
if ( run_opencl_kernel_bzero ( hashcat_ctx , device_param , device_param - > opencl_d_result , sizeof ( u32 ) ) = = - 1 ) return - 1 ;
if ( hc_clFlush ( hashcat_ctx , device_param - > opencl_command_queue ) = = - 1 ) return - 1 ;
2016-09-14 14:07:24 +00:00
}
return 0 ;
}
2016-09-16 15:01:18 +00:00
2019-02-25 10:20:22 +00:00
int hashes_init_filename ( hashcat_ctx_t * hashcat_ctx )
2016-09-16 15:01:18 +00:00
{
2016-10-06 08:55:14 +00:00
hashconfig_t * hashconfig = hashcat_ctx - > hashconfig ;
hashes_t * hashes = hashcat_ctx - > hashes ;
user_options_t * user_options = hashcat_ctx - > user_options ;
user_options_extra_t * user_options_extra = hashcat_ctx - > user_options_extra ;
2021-05-01 12:13:58 +00:00
if ( user_options - > benchmark = = true ) return 0 ;
2016-09-16 15:01:18 +00:00
/**
* load hashes , part I : find input mode , count hashes
*/
2019-02-25 10:20:22 +00:00
if ( hashconfig - > opts_type & OPTS_TYPE_BINARY_HASHFILE )
2016-09-16 15:01:18 +00:00
{
2021-04-04 09:38:02 +00:00
if ( hashconfig - > opts_type & OPTS_TYPE_BINARY_HASHFILE_OPTIONAL )
2017-12-06 15:12:34 +00:00
{
2021-04-04 09:38:02 +00:00
if ( ( user_options - > benchmark = = false ) & & ( user_options - > keyspace = = false ) )
2017-12-06 15:12:34 +00:00
{
2021-04-04 09:38:02 +00:00
hashes - > hashlist_mode = ( hc_path_exist ( user_options_extra - > hc_hash ) = = true ) ? HL_MODE_FILE_PLAIN : HL_MODE_ARG ;
2016-09-16 15:01:18 +00:00
2021-04-04 09:38:02 +00:00
if ( hashes - > hashlist_mode = = HL_MODE_FILE_PLAIN )
{
hashes - > hashfile = user_options_extra - > hc_hash ;
}
2017-12-06 15:12:34 +00:00
}
2021-04-04 09:38:02 +00:00
}
else
{
hashes - > hashlist_mode = HL_MODE_FILE_BINARY ;
2019-02-25 10:20:22 +00:00
2021-04-04 09:38:02 +00:00
if ( ( user_options - > benchmark = = false ) & & ( user_options - > keyspace = = false ) )
{
if ( hc_path_read ( user_options_extra - > hc_hash ) = = false )
{
event_log_error ( hashcat_ctx , " %s: %s " , user_options_extra - > hc_hash , strerror ( errno ) ) ;
return - 1 ;
}
hashes - > hashfile = user_options_extra - > hc_hash ;
}
2016-09-16 15:01:18 +00:00
}
2017-12-06 15:12:34 +00:00
}
else
{
2019-02-25 10:20:22 +00:00
hashes - > hashlist_mode = ( hc_path_exist ( user_options_extra - > hc_hash ) = = true ) ? HL_MODE_FILE_PLAIN : HL_MODE_ARG ;
if ( hashes - > hashlist_mode = = HL_MODE_FILE_PLAIN )
{
hashes - > hashfile = user_options_extra - > hc_hash ;
}
2017-12-06 15:12:34 +00:00
}
2019-02-25 10:20:22 +00:00
2022-05-04 12:26:53 +00:00
hashes - > parser_token_length_cnt = 0 ;
2019-02-25 10:20:22 +00:00
return 0 ;
2017-12-06 15:12:34 +00:00
}
2016-09-16 15:01:18 +00:00
2017-12-06 15:12:34 +00:00
int hashes_init_stage1 ( hashcat_ctx_t * hashcat_ctx )
{
hashconfig_t * hashconfig = hashcat_ctx - > hashconfig ;
hashes_t * hashes = hashcat_ctx - > hashes ;
2018-12-14 11:22:13 +00:00
module_ctx_t * module_ctx = hashcat_ctx - > module_ctx ;
2017-12-06 15:12:34 +00:00
user_options_t * user_options = hashcat_ctx - > user_options ;
user_options_extra_t * user_options_extra = hashcat_ctx - > user_options_extra ;
/**
* load hashes , part I : find input mode , count hashes
*/
const char * hashfile = hashes - > hashfile ;
const u32 hashlist_mode = hashes - > hashlist_mode ;
u32 hashlist_format = HLFMT_HASHCAT ;
2018-02-08 18:13:29 +00:00
u64 hashes_avail = 0 ;
2017-12-06 15:12:34 +00:00
if ( ( user_options - > benchmark = = false ) & & ( user_options - > stdout_flag = = false ) & & ( user_options - > keyspace = = false ) )
{
2016-09-16 15:01:18 +00:00
if ( hashlist_mode = = HL_MODE_ARG )
{
2019-02-25 10:20:22 +00:00
hashes_avail = 1 ;
2016-09-16 15:01:18 +00:00
}
2019-02-25 10:20:22 +00:00
else if ( hashlist_mode = = HL_MODE_FILE_PLAIN )
2016-09-16 15:01:18 +00:00
{
2019-06-26 17:06:46 +00:00
HCFILE fp ;
2016-09-16 15:01:18 +00:00
2019-07-01 15:27:08 +00:00
if ( hc_fopen ( & fp , hashfile , " rb " ) = = false )
2016-09-16 15:01:18 +00:00
{
2017-02-04 01:53:50 +00:00
event_log_error ( hashcat_ctx , " %s: %s " , hashfile , strerror ( errno ) ) ;
2016-09-16 15:01:18 +00:00
return - 1 ;
}
2016-11-02 23:07:01 +00:00
EVENT_DATA ( EVENT_HASHLIST_COUNT_LINES_PRE , hashfile , strlen ( hashfile ) ) ;
2016-09-16 15:01:18 +00:00
2019-06-26 17:06:46 +00:00
hashes_avail = count_lines ( & fp ) ;
2016-09-16 15:01:18 +00:00
2016-11-02 23:07:01 +00:00
EVENT_DATA ( EVENT_HASHLIST_COUNT_LINES_POST , hashfile , strlen ( hashfile ) ) ;
2016-10-23 12:49:40 +00:00
2019-06-26 17:06:46 +00:00
hc_rewind ( & fp ) ;
2016-09-16 15:01:18 +00:00
if ( hashes_avail = = 0 )
{
2017-04-02 07:50:06 +00:00
event_log_error ( hashcat_ctx , " hashfile is empty or corrupt. " ) ;
2016-09-16 15:01:18 +00:00
2019-06-26 17:06:46 +00:00
hc_fclose ( & fp ) ;
2016-09-16 15:01:18 +00:00
return - 1 ;
}
2019-06-26 17:06:46 +00:00
hashlist_format = hlfmt_detect ( hashcat_ctx , & fp , 100 ) ; // 100 = max numbers to "scan". could be hashes_avail, too
2019-06-21 19:56:38 +00:00
2019-06-26 17:06:46 +00:00
hc_fclose ( & fp ) ;
2016-09-16 15:01:18 +00:00
2017-03-12 10:05:37 +00:00
if ( ( user_options - > remove = = true ) & & ( hashlist_format ! = HLFMT_HASHCAT ) )
2016-09-16 15:01:18 +00:00
{
2017-04-02 07:50:06 +00:00
event_log_error ( hashcat_ctx , " Use of --remove is not supported in native hashfile-format mode. " ) ;
2016-09-16 15:01:18 +00:00
return - 1 ;
}
}
2019-02-25 10:20:22 +00:00
else if ( hashlist_mode = = HL_MODE_FILE_BINARY )
{
struct stat st ;
if ( stat ( hashes - > hashfile , & st ) = = - 1 )
{
event_log_error ( hashcat_ctx , " %s: %s " , hashes - > hashfile , strerror ( errno ) ) ;
return - 1 ;
}
if ( module_ctx - > module_hash_binary_count ! = MODULE_DEFAULT )
{
const int binary_count = module_ctx - > module_hash_binary_count ( hashes ) ;
2020-05-27 13:23:02 +00:00
if ( binary_count > 0 )
{
hashes_avail = binary_count ;
}
else if ( binary_count = = 0 )
2019-03-17 14:01:41 +00:00
{
event_log_error ( hashcat_ctx , " No hashes loaded. " ) ;
return - 1 ;
}
2020-05-27 13:23:02 +00:00
else if ( binary_count = = PARSER_HAVE_ERRNO )
2019-02-25 10:20:22 +00:00
{
event_log_error ( hashcat_ctx , " %s: %s " , hashes - > hashfile , strerror ( errno ) ) ;
return - 1 ;
}
2020-05-27 13:23:02 +00:00
else
{
event_log_error ( hashcat_ctx , " %s: %s " , hashes - > hashfile , strerror ( binary_count ) ) ;
2019-02-25 10:20:22 +00:00
2020-05-27 13:23:02 +00:00
return - 1 ;
}
2019-02-25 10:20:22 +00:00
}
else
{
hashes_avail = 1 ;
}
}
2016-09-16 15:01:18 +00:00
}
else
{
hashes_avail = 1 ;
}
2019-01-08 14:55:11 +00:00
if ( hashconfig - > opts_type & OPTS_TYPE_HASH_SPLIT ) hashes_avail * = 2 ;
2016-09-16 15:01:18 +00:00
hashes - > hashlist_format = hashlist_format ;
/**
* load hashes , part II : allocate required memory , set pointers
*/
2017-02-11 11:19:34 +00:00
hash_t * hashes_buf = ( hash_t * ) hccalloc ( hashes_avail , sizeof ( hash_t ) ) ;
2017-11-05 08:52:29 +00:00
void * digests_buf = hccalloc ( hashes_avail , hashconfig - > dgst_size ) ;
2017-01-24 14:23:48 +00:00
salt_t * salts_buf = NULL ;
void * esalts_buf = NULL ;
void * hook_salts_buf = NULL ;
2016-09-16 15:01:18 +00:00
2017-02-13 15:46:37 +00:00
if ( ( user_options - > username = = true ) | | ( hashconfig - > opts_type & OPTS_TYPE_HASH_COPY ) | | ( hashconfig - > opts_type & OPTS_TYPE_HASH_SPLIT ) )
2016-09-16 15:01:18 +00:00
{
2019-08-04 05:34:48 +00:00
u64 hash_pos ;
2016-09-16 15:01:18 +00:00
for ( hash_pos = 0 ; hash_pos < hashes_avail ; hash_pos + + )
{
2016-11-20 21:54:52 +00:00
hashinfo_t * hash_info = ( hashinfo_t * ) hcmalloc ( sizeof ( hashinfo_t ) ) ;
2016-09-16 15:01:18 +00:00
hashes_buf [ hash_pos ] . hash_info = hash_info ;
2016-10-19 10:42:41 +00:00
if ( user_options - > username = = true )
2016-09-16 15:01:18 +00:00
{
2017-02-13 15:46:37 +00:00
hash_info - > user = ( user_t * ) hcmalloc ( sizeof ( user_t ) ) ;
2016-09-16 15:01:18 +00:00
}
2017-01-24 09:28:35 +00:00
if ( hashconfig - > opts_type & OPTS_TYPE_HASH_COPY )
2016-09-16 15:01:18 +00:00
{
2017-01-24 09:28:35 +00:00
if ( user_options - > benchmark = = false )
{
hash_info - > orighash = ( char * ) hcmalloc ( 256 ) ;
}
}
2017-02-13 15:46:37 +00:00
if ( hashconfig - > opts_type & OPTS_TYPE_HASH_SPLIT )
{
hash_info - > split = ( split_t * ) hcmalloc ( sizeof ( split_t ) ) ;
}
2016-09-16 15:01:18 +00:00
}
}
2017-09-16 20:33:04 +00:00
if ( hashconfig - > is_salted = = true )
2016-09-16 15:01:18 +00:00
{
2016-11-20 21:54:52 +00:00
salts_buf = ( salt_t * ) hccalloc ( hashes_avail , sizeof ( salt_t ) ) ;
2016-09-16 15:01:18 +00:00
2020-09-29 13:56:32 +00:00
if ( user_options - > attack_mode = = ATTACK_MODE_ASSOCIATION )
{
// this disables:
// - sorting by salt value
// - grouping by salt value
// - keep the salt in position relative to hashfile (not equal because of some hashes maybe failed to load)
u64 hash_pos ;
for ( hash_pos = 0 ; hash_pos < hashes_avail ; hash_pos + + )
{
salt_t * salt = & salts_buf [ hash_pos ] ;
salt - > orig_pos = hash_pos ;
}
}
2017-09-16 20:33:04 +00:00
if ( hashconfig - > esalt_size > 0 )
2016-09-16 15:01:18 +00:00
{
2017-11-05 08:52:29 +00:00
esalts_buf = hccalloc ( hashes_avail , hashconfig - > esalt_size ) ;
2016-09-16 15:01:18 +00:00
}
2017-01-24 14:23:48 +00:00
2017-09-16 20:33:04 +00:00
if ( hashconfig - > hook_salt_size > 0 )
2017-01-24 14:23:48 +00:00
{
2019-01-08 14:55:11 +00:00
hook_salts_buf = hccalloc ( hashes_avail , hashconfig - > hook_salt_size ) ;
2017-01-24 14:23:48 +00:00
}
2016-09-16 15:01:18 +00:00
}
else
{
2016-11-20 21:54:52 +00:00
salts_buf = ( salt_t * ) hccalloc ( 1 , sizeof ( salt_t ) ) ;
2016-09-16 15:01:18 +00:00
}
2019-08-04 05:34:48 +00:00
for ( u64 hash_pos = 0 ; hash_pos < hashes_avail ; hash_pos + + )
2016-09-16 15:01:18 +00:00
{
2019-11-05 12:49:22 +00:00
/**
* Initialize some values for later use
*/
hashes_buf [ hash_pos ] . orig_line_pos = hash_pos ;
2016-09-16 15:01:18 +00:00
hashes_buf [ hash_pos ] . digest = ( ( char * ) digests_buf ) + ( hash_pos * hashconfig - > dgst_size ) ;
2017-09-16 20:33:04 +00:00
if ( hashconfig - > is_salted = = true )
2016-09-16 15:01:18 +00:00
{
hashes_buf [ hash_pos ] . salt = & salts_buf [ hash_pos ] ;
2017-09-16 20:33:04 +00:00
if ( hashconfig - > esalt_size > 0 )
2016-09-16 15:01:18 +00:00
{
hashes_buf [ hash_pos ] . esalt = ( ( char * ) esalts_buf ) + ( hash_pos * hashconfig - > esalt_size ) ;
}
2017-01-24 14:23:48 +00:00
2017-09-16 20:33:04 +00:00
if ( hashconfig - > hook_salt_size > 0 )
2017-01-24 14:23:48 +00:00
{
hashes_buf [ hash_pos ] . hook_salt = ( ( char * ) hook_salts_buf ) + ( hash_pos * hashconfig - > hook_salt_size ) ;
}
2016-09-16 15:01:18 +00:00
}
else
{
hashes_buf [ hash_pos ] . salt = & salts_buf [ 0 ] ;
}
}
2017-01-24 14:23:48 +00:00
hashes - > hashes_buf = hashes_buf ;
hashes - > digests_buf = digests_buf ;
hashes - > salts_buf = salts_buf ;
hashes - > esalts_buf = esalts_buf ;
hashes - > hook_salts_buf = hook_salts_buf ;
2016-09-16 15:01:18 +00:00
/**
2019-01-12 00:59:18 +00:00
* load hashes , part III : parse hashes
2016-09-16 15:01:18 +00:00
*/
2016-10-04 04:35:49 +00:00
u32 hashes_cnt = 0 ;
2016-09-16 15:01:18 +00:00
2016-09-21 14:07:49 +00:00
if ( user_options - > benchmark = = true )
2016-09-16 15:01:18 +00:00
{
2016-09-21 14:07:49 +00:00
hashes - > hashfile = " - " ;
hashes_cnt = 1 ;
}
2020-12-29 03:58:58 +00:00
else if ( user_options - > hash_info = = true )
{
}
2016-09-21 14:07:49 +00:00
else if ( user_options - > keyspace = = true )
{
}
else if ( user_options - > stdout_flag = = true )
{
}
2022-02-13 11:33:11 +00:00
else if ( user_options - > backend_info > 0 )
2016-09-21 14:07:49 +00:00
{
}
else
{
2019-02-25 10:20:22 +00:00
if ( hashlist_mode = = HL_MODE_ARG )
2016-09-16 15:01:18 +00:00
{
2017-12-06 15:12:34 +00:00
char * input_buf = user_options_extra - > hc_hash ;
2016-09-16 15:01:18 +00:00
2018-02-08 18:13:29 +00:00
size_t input_len = strlen ( input_buf ) ;
2016-09-16 15:01:18 +00:00
2018-02-08 18:13:29 +00:00
char * hash_buf = NULL ;
2018-12-14 11:22:13 +00:00
int hash_len = 0 ;
2016-09-16 15:01:18 +00:00
2016-10-06 19:12:32 +00:00
hlfmt_hash ( hashcat_ctx , hashlist_format , input_buf , input_len , & hash_buf , & hash_len ) ;
2016-09-16 15:01:18 +00:00
2019-09-10 00:52:08 +00:00
bool hash_fmt_error = false ;
2016-09-16 15:01:18 +00:00
2019-09-10 00:52:08 +00:00
if ( hash_len < 1 ) hash_fmt_error = true ;
if ( hash_buf = = NULL ) hash_fmt_error = true ;
2016-09-16 15:01:18 +00:00
if ( hash_fmt_error )
{
2017-04-02 07:50:06 +00:00
event_log_warning ( hashcat_ctx , " Failed to parse hashes using the '%s' format. " , strhlfmt ( hashlist_format ) ) ;
2016-09-16 15:01:18 +00:00
}
else
{
if ( hashconfig - > opts_type & OPTS_TYPE_HASH_COPY )
{
hashinfo_t * hash_info_tmp = hashes_buf [ hashes_cnt ] . hash_info ;
2016-11-20 21:54:52 +00:00
hash_info_tmp - > orighash = hcstrdup ( hash_buf ) ;
2016-09-16 15:01:18 +00:00
}
2017-09-16 20:33:04 +00:00
if ( hashconfig - > is_salted = = true )
2016-09-16 15:01:18 +00:00
{
memset ( hashes_buf [ 0 ] . salt , 0 , sizeof ( salt_t ) ) ;
}
2017-09-16 20:33:04 +00:00
if ( hashconfig - > esalt_size > 0 )
2017-02-21 12:09:00 +00:00
{
memset ( hashes_buf [ 0 ] . esalt , 0 , hashconfig - > esalt_size ) ;
}
2017-09-16 20:33:04 +00:00
if ( hashconfig - > hook_salt_size > 0 )
2017-02-21 12:09:00 +00:00
{
memset ( hashes_buf [ 0 ] . hook_salt , 0 , hashconfig - > hook_salt_size ) ;
}
2016-09-16 15:01:18 +00:00
int parser_status = PARSER_OK ;
2021-08-12 21:53:52 +00:00
if ( user_options - > username = = true )
{
char * user_buf = NULL ;
int user_len = 0 ;
hlfmt_user ( hashcat_ctx , hashlist_format , input_buf , input_len , & user_buf , & user_len ) ;
// special case:
// both hash_t need to have the username info if the pwdump format is used (i.e. we have 2 hashes for 3000, both with same user)
u32 hashes_per_user = 1 ;
if ( hashconfig - > opts_type & OPTS_TYPE_HASH_SPLIT )
{
// the following conditions should be true if (hashlist_format == HLFMT_PWDUMP)
if ( hash_len = = 32 )
{
hashes_per_user = 2 ;
}
}
for ( u32 i = 0 ; i < hashes_per_user ; i + + )
{
user_t * * user = & hashes_buf [ hashes_cnt + i ] . hash_info - > user ;
* user = ( user_t * ) hcmalloc ( sizeof ( user_t ) ) ;
user_t * user_ptr = * user ;
if ( user_buf ! = NULL )
{
user_ptr - > user_name = hcstrdup ( user_buf ) ;
}
else
{
user_ptr - > user_name = hcstrdup ( " " ) ;
}
user_ptr - > user_len = ( u32 ) user_len ;
}
}
2019-01-08 14:55:11 +00:00
if ( hashconfig - > opts_type & OPTS_TYPE_HASH_SPLIT )
2016-09-16 15:01:18 +00:00
{
if ( hash_len = = 32 )
{
2018-12-14 11:22:13 +00:00
hash_t * hash ;
hash = & hashes_buf [ hashes_cnt ] ;
2019-01-25 10:14:04 +00:00
parser_status = module_ctx - > module_hash_decode ( hashconfig , hash - > digest , hash - > salt , hash - > esalt , hash - > hook_salt , hash - > hash_info , hash_buf + 0 , 16 ) ;
2016-09-16 15:01:18 +00:00
if ( parser_status = = PARSER_OK )
{
2021-11-28 12:58:27 +00:00
if ( module_ctx - > module_hash_decode_postprocess ! = MODULE_DEFAULT )
{
parser_status = module_ctx - > module_hash_decode_postprocess ( hashconfig , hash - > digest , hash - > salt , hash - > esalt , hash - > hook_salt , hash - > hash_info , user_options , user_options_extra ) ;
if ( parser_status = = PARSER_OK )
{
// nothing to do
}
else
{
event_log_warning ( hashcat_ctx , " Hash '%s': %s " , input_buf , strparser ( parser_status ) ) ;
}
}
2017-02-13 15:46:37 +00:00
hashes_buf [ hashes_cnt ] . hash_info - > split - > split_group = 0 ;
hashes_buf [ hashes_cnt ] . hash_info - > split - > split_origin = SPLIT_ORIGIN_LEFT ;
2016-09-16 15:01:18 +00:00
hashes_cnt + + ;
}
else
{
2016-10-09 20:41:55 +00:00
event_log_warning ( hashcat_ctx , " Hash '%s': %s " , input_buf , strparser ( parser_status ) ) ;
2016-09-16 15:01:18 +00:00
}
2022-05-04 12:26:53 +00:00
if ( parser_status = = PARSER_TOKEN_LENGTH )
{
hashes - > parser_token_length_cnt + + ;
}
2018-12-14 11:22:13 +00:00
hash = & hashes_buf [ hashes_cnt ] ;
2019-01-25 10:14:04 +00:00
parser_status = module_ctx - > module_hash_decode ( hashconfig , hash - > digest , hash - > salt , hash - > esalt , hash - > hook_salt , hash - > hash_info , hash_buf + 16 , 16 ) ;
2016-09-16 15:01:18 +00:00
if ( parser_status = = PARSER_OK )
{
2021-11-28 12:58:27 +00:00
if ( module_ctx - > module_hash_decode_postprocess ! = MODULE_DEFAULT )
{
parser_status = module_ctx - > module_hash_decode_postprocess ( hashconfig , hash - > digest , hash - > salt , hash - > esalt , hash - > hook_salt , hash - > hash_info , user_options , user_options_extra ) ;
if ( parser_status = = PARSER_OK )
{
// nothing to do
}
else
{
event_log_warning ( hashcat_ctx , " Hash '%s': %s " , input_buf , strparser ( parser_status ) ) ;
}
}
2017-02-13 15:46:37 +00:00
hashes_buf [ hashes_cnt ] . hash_info - > split - > split_group = 0 ;
hashes_buf [ hashes_cnt ] . hash_info - > split - > split_origin = SPLIT_ORIGIN_RIGHT ;
2016-09-16 15:01:18 +00:00
hashes_cnt + + ;
}
else
{
2016-10-09 20:41:55 +00:00
event_log_warning ( hashcat_ctx , " Hash '%s': %s " , input_buf , strparser ( parser_status ) ) ;
2016-09-16 15:01:18 +00:00
}
2022-05-04 12:26:53 +00:00
if ( parser_status = = PARSER_TOKEN_LENGTH )
{
hashes - > parser_token_length_cnt + + ;
}
2016-09-16 15:01:18 +00:00
}
else
{
2018-12-14 11:22:13 +00:00
hash_t * hash = & hashes_buf [ hashes_cnt ] ;
2019-01-25 10:14:04 +00:00
parser_status = module_ctx - > module_hash_decode ( hashconfig , hash - > digest , hash - > salt , hash - > esalt , hash - > hook_salt , hash - > hash_info , hash_buf , hash_len ) ;
2016-09-16 15:01:18 +00:00
if ( parser_status = = PARSER_OK )
{
2021-11-28 12:58:27 +00:00
if ( module_ctx - > module_hash_decode_postprocess ! = MODULE_DEFAULT )
{
parser_status = module_ctx - > module_hash_decode_postprocess ( hashconfig , hash - > digest , hash - > salt , hash - > esalt , hash - > hook_salt , hash - > hash_info , user_options , user_options_extra ) ;
if ( parser_status = = PARSER_OK )
{
// nothing to do
}
else
{
event_log_warning ( hashcat_ctx , " Hash '%s': %s " , input_buf , strparser ( parser_status ) ) ;
}
}
2017-02-13 15:46:37 +00:00
hashes_buf [ hashes_cnt ] . hash_info - > split - > split_group = 0 ;
hashes_buf [ hashes_cnt ] . hash_info - > split - > split_origin = SPLIT_ORIGIN_NONE ;
2016-09-16 15:01:18 +00:00
hashes_cnt + + ;
}
else
{
2016-10-09 20:41:55 +00:00
event_log_warning ( hashcat_ctx , " Hash '%s': %s " , input_buf , strparser ( parser_status ) ) ;
2016-09-16 15:01:18 +00:00
}
2022-05-04 12:26:53 +00:00
if ( parser_status = = PARSER_TOKEN_LENGTH )
{
hashes - > parser_token_length_cnt + + ;
}
2016-09-16 15:01:18 +00:00
}
}
2019-01-08 14:55:11 +00:00
else
2017-01-21 14:37:44 +00:00
{
2019-02-25 10:20:22 +00:00
hash_t * hash = & hashes_buf [ hashes_cnt ] ;
2017-01-21 14:37:44 +00:00
2019-02-25 10:20:22 +00:00
parser_status = module_ctx - > module_hash_decode ( hashconfig , hash - > digest , hash - > salt , hash - > esalt , hash - > hook_salt , hash - > hash_info , hash_buf , hash_len ) ;
if ( parser_status = = PARSER_OK )
{
2021-11-28 12:58:27 +00:00
if ( module_ctx - > module_hash_decode_postprocess ! = MODULE_DEFAULT )
{
parser_status = module_ctx - > module_hash_decode_postprocess ( hashconfig , hash - > digest , hash - > salt , hash - > esalt , hash - > hook_salt , hash - > hash_info , user_options , user_options_extra ) ;
if ( parser_status = = PARSER_OK )
{
// nothing to do
}
else
{
event_log_warning ( hashcat_ctx , " Hash '%s': %s " , input_buf , strparser ( parser_status ) ) ;
}
}
2019-02-25 10:20:22 +00:00
hashes_cnt + + ;
2016-09-16 15:01:18 +00:00
}
else
{
2019-02-25 10:20:22 +00:00
event_log_warning ( hashcat_ctx , " Hash '%s': %s " , input_buf , strparser ( parser_status ) ) ;
2016-09-16 15:01:18 +00:00
}
2022-05-04 12:26:53 +00:00
if ( parser_status = = PARSER_TOKEN_LENGTH )
{
hashes - > parser_token_length_cnt + + ;
}
2016-09-16 15:01:18 +00:00
}
}
}
2019-02-25 10:20:22 +00:00
else if ( hashlist_mode = = HL_MODE_FILE_PLAIN )
2016-09-16 15:01:18 +00:00
{
2019-06-26 17:06:46 +00:00
HCFILE fp ;
2016-09-16 15:01:18 +00:00
2019-07-01 15:27:08 +00:00
if ( hc_fopen ( & fp , hashfile , " rb " ) = = false )
2016-09-16 15:01:18 +00:00
{
2017-02-04 01:53:50 +00:00
event_log_error ( hashcat_ctx , " %s: %s " , hashfile , strerror ( errno ) ) ;
2016-09-16 15:01:18 +00:00
return - 1 ;
}
2016-10-04 04:35:49 +00:00
u32 line_num = 0 ;
2016-09-16 15:01:18 +00:00
2016-11-20 21:54:52 +00:00
char * line_buf = ( char * ) hcmalloc ( HCBUFSIZ_LARGE ) ;
2016-09-16 15:01:18 +00:00
2017-12-10 00:40:45 +00:00
time_t prev = 0 ;
time_t now = 0 ;
2016-10-23 12:49:40 +00:00
2019-06-26 17:06:46 +00:00
while ( ! hc_feof ( & fp ) )
2016-09-16 15:01:18 +00:00
{
line_num + + ;
2019-08-06 10:22:24 +00:00
const size_t line_len = fgetl ( & fp , line_buf , HCBUFSIZ_LARGE ) ;
2016-09-16 15:01:18 +00:00
if ( line_len = = 0 ) continue ;
2016-11-08 15:41:11 +00:00
if ( hashes_avail = = hashes_cnt )
{
2017-04-02 07:50:06 +00:00
event_log_warning ( hashcat_ctx , " Hashfile '%s' on line %u: File changed during runtime. Skipping new data. " , hashes - > hashfile , line_num ) ;
2016-11-08 15:41:11 +00:00
break ;
}
2018-12-14 11:22:13 +00:00
char * hash_buf = NULL ;
int hash_len = 0 ;
2016-09-16 15:01:18 +00:00
2016-10-06 19:12:32 +00:00
hlfmt_hash ( hashcat_ctx , hashlist_format , line_buf , line_len , & hash_buf , & hash_len ) ;
2016-09-16 15:01:18 +00:00
2019-09-10 00:52:08 +00:00
bool hash_fmt_error = false ;
2016-09-16 15:01:18 +00:00
2019-09-10 00:52:08 +00:00
if ( hash_len < 1 ) hash_fmt_error = true ;
if ( hash_buf = = NULL ) hash_fmt_error = true ;
2016-09-16 15:01:18 +00:00
if ( hash_fmt_error )
{
2017-04-02 07:50:06 +00:00
event_log_warning ( hashcat_ctx , " Failed to parse hashes using the '%s' format. " , strhlfmt ( hashlist_format ) ) ;
2016-09-16 15:01:18 +00:00
continue ;
}
2016-10-19 10:42:41 +00:00
if ( user_options - > username = = true )
2016-09-16 15:01:18 +00:00
{
2018-12-14 11:22:13 +00:00
char * user_buf = NULL ;
int user_len = 0 ;
2016-09-16 15:01:18 +00:00
2016-10-06 19:12:32 +00:00
hlfmt_user ( hashcat_ctx , hashlist_format , line_buf , line_len , & user_buf , & user_len ) ;
2016-09-16 15:01:18 +00:00
2017-01-27 11:30:27 +00:00
// special case:
// both hash_t need to have the username info if the pwdump format is used (i.e. we have 2 hashes for 3000, both with same user)
2016-09-16 15:01:18 +00:00
2017-01-27 11:30:27 +00:00
u32 hashes_per_user = 1 ;
2016-09-16 15:01:18 +00:00
2019-01-08 14:55:11 +00:00
if ( hashconfig - > opts_type & OPTS_TYPE_HASH_SPLIT )
2016-10-19 10:42:41 +00:00
{
2019-01-08 14:55:11 +00:00
// the following conditions should be true if (hashlist_format == HLFMT_PWDUMP)
2017-01-27 11:30:27 +00:00
if ( hash_len = = 32 )
{
hashes_per_user = 2 ;
}
2016-10-19 10:42:41 +00:00
}
2017-01-27 11:30:27 +00:00
for ( u32 i = 0 ; i < hashes_per_user ; i + + )
2016-10-19 10:42:41 +00:00
{
2017-01-27 11:30:27 +00:00
user_t * * user = & hashes_buf [ hashes_cnt + i ] . hash_info - > user ;
* user = ( user_t * ) hcmalloc ( sizeof ( user_t ) ) ;
user_t * user_ptr = * user ;
2016-10-19 10:42:41 +00:00
2017-01-27 11:30:27 +00:00
if ( user_buf ! = NULL )
{
user_ptr - > user_name = hcstrdup ( user_buf ) ;
}
else
{
user_ptr - > user_name = hcstrdup ( " " ) ;
}
2018-02-08 18:13:29 +00:00
user_ptr - > user_len = ( u32 ) user_len ;
2017-01-27 11:30:27 +00:00
}
2016-09-16 15:01:18 +00:00
}
if ( hashconfig - > opts_type & OPTS_TYPE_HASH_COPY )
{
hashinfo_t * hash_info_tmp = hashes_buf [ hashes_cnt ] . hash_info ;
2016-11-20 21:54:52 +00:00
hash_info_tmp - > orighash = hcstrdup ( hash_buf ) ;
2016-09-16 15:01:18 +00:00
}
2017-09-16 20:33:04 +00:00
if ( hashconfig - > is_salted = = true )
2016-09-16 15:01:18 +00:00
{
2020-09-29 13:56:32 +00:00
const u32 orig_pos = hashes_buf [ hashes_cnt ] . salt - > orig_pos ;
2016-09-16 15:01:18 +00:00
memset ( hashes_buf [ hashes_cnt ] . salt , 0 , sizeof ( salt_t ) ) ;
2020-09-29 13:56:32 +00:00
hashes_buf [ hashes_cnt ] . salt - > orig_pos = orig_pos ;
2016-09-16 15:01:18 +00:00
}
2017-09-16 20:33:04 +00:00
if ( hashconfig - > esalt_size > 0 )
2017-02-21 12:09:00 +00:00
{
memset ( hashes_buf [ hashes_cnt ] . esalt , 0 , hashconfig - > esalt_size ) ;
}
2017-09-16 20:33:04 +00:00
if ( hashconfig - > hook_salt_size > 0 )
2017-02-21 12:09:00 +00:00
{
memset ( hashes_buf [ hashes_cnt ] . hook_salt , 0 , hashconfig - > hook_salt_size ) ;
}
2019-01-08 14:55:11 +00:00
if ( hashconfig - > opts_type & OPTS_TYPE_HASH_SPLIT )
2016-09-16 15:01:18 +00:00
{
if ( hash_len = = 32 )
{
2018-12-14 11:22:13 +00:00
hash_t * hash ;
hash = & hashes_buf [ hashes_cnt ] ;
2019-01-25 10:14:04 +00:00
int parser_status = module_ctx - > module_hash_decode ( hashconfig , hash - > digest , hash - > salt , hash - > esalt , hash - > hook_salt , hash - > hash_info , hash_buf + 0 , 16 ) ;
2016-09-16 15:01:18 +00:00
if ( parser_status < PARSER_GLOBAL_ZERO )
{
2017-11-17 08:50:52 +00:00
char * tmp_line_buf ;
2017-11-16 11:37:31 +00:00
2017-11-17 08:50:52 +00:00
hc_asprintf ( & tmp_line_buf , " %s " , line_buf ) ;
2017-11-16 11:37:31 +00:00
compress_terminal_line_length ( tmp_line_buf , 38 , 32 ) ;
2021-04-28 07:48:33 +00:00
if ( user_options - > machine_readable = = true )
{
event_log_warning ( hashcat_ctx , " %s:%u:%s:%s " , hashes - > hashfile , line_num , tmp_line_buf , strparser ( parser_status ) ) ;
}
else
{
event_log_warning ( hashcat_ctx , " Hashfile '%s' on line %u (%s): %s " , hashes - > hashfile , line_num , tmp_line_buf , strparser ( parser_status ) ) ;
2021-04-04 13:11:07 +00:00
}
2017-11-16 11:37:31 +00:00
hcfree ( tmp_line_buf ) ;
2016-09-16 15:01:18 +00:00
continue ;
}
2021-11-28 12:58:27 +00:00
if ( module_ctx - > module_hash_decode_postprocess ! = MODULE_DEFAULT )
{
int parser_status_postprocess = module_ctx - > module_hash_decode_postprocess ( hashconfig , hash - > digest , hash - > salt , hash - > esalt , hash - > hook_salt , hash - > hash_info , user_options , user_options_extra ) ;
if ( parser_status_postprocess < PARSER_GLOBAL_ZERO )
{
char * tmp_line_buf ;
hc_asprintf ( & tmp_line_buf , " %s " , line_buf ) ;
compress_terminal_line_length ( tmp_line_buf , 38 , 32 ) ;
if ( user_options - > machine_readable = = true )
{
event_log_warning ( hashcat_ctx , " %s:%u:%s:%s " , hashes - > hashfile , line_num , tmp_line_buf , strparser ( parser_status_postprocess ) ) ;
}
else
{
event_log_warning ( hashcat_ctx , " Hashfile '%s' on line %u (%s): %s " , hashes - > hashfile , line_num , tmp_line_buf , strparser ( parser_status_postprocess ) ) ;
}
hcfree ( tmp_line_buf ) ;
continue ;
}
}
2017-02-13 15:46:37 +00:00
hashes_buf [ hashes_cnt ] . hash_info - > split - > split_group = line_num ;
hashes_buf [ hashes_cnt ] . hash_info - > split - > split_origin = SPLIT_ORIGIN_LEFT ;
2016-09-16 15:01:18 +00:00
hashes_cnt + + ;
2018-12-14 11:22:13 +00:00
hash = & hashes_buf [ hashes_cnt ] ;
2019-01-25 10:14:04 +00:00
parser_status = module_ctx - > module_hash_decode ( hashconfig , hash - > digest , hash - > salt , hash - > esalt , hash - > hook_salt , hash - > hash_info , hash_buf + 16 , 16 ) ;
2016-09-16 15:01:18 +00:00
if ( parser_status < PARSER_GLOBAL_ZERO )
{
2017-11-17 08:50:52 +00:00
char * tmp_line_buf ;
2017-11-16 11:37:31 +00:00
2017-11-17 08:50:52 +00:00
hc_asprintf ( & tmp_line_buf , " %s " , line_buf ) ;
2017-11-16 11:37:31 +00:00
compress_terminal_line_length ( tmp_line_buf , 38 , 32 ) ;
2021-04-28 07:48:33 +00:00
if ( user_options - > machine_readable = = true )
{
event_log_warning ( hashcat_ctx , " %s:%u:%s:%s " , hashes - > hashfile , line_num , tmp_line_buf , strparser ( parser_status ) ) ;
}
else
{
event_log_warning ( hashcat_ctx , " Hashfile '%s' on line %u (%s): %s " , hashes - > hashfile , line_num , tmp_line_buf , strparser ( parser_status ) ) ;
2021-04-04 13:11:07 +00:00
}
2017-11-16 11:37:31 +00:00
hcfree ( tmp_line_buf ) ;
2016-09-16 15:01:18 +00:00
continue ;
}
2021-11-28 12:58:27 +00:00
if ( module_ctx - > module_hash_decode_postprocess ! = MODULE_DEFAULT )
{
int parser_status_postprocess = module_ctx - > module_hash_decode_postprocess ( hashconfig , hash - > digest , hash - > salt , hash - > esalt , hash - > hook_salt , hash - > hash_info , user_options , user_options_extra ) ;
if ( parser_status_postprocess < PARSER_GLOBAL_ZERO )
{
char * tmp_line_buf ;
hc_asprintf ( & tmp_line_buf , " %s " , line_buf ) ;
compress_terminal_line_length ( tmp_line_buf , 38 , 32 ) ;
if ( user_options - > machine_readable = = true )
{
event_log_warning ( hashcat_ctx , " %s:%u:%s:%s " , hashes - > hashfile , line_num , tmp_line_buf , strparser ( parser_status_postprocess ) ) ;
}
else
{
event_log_warning ( hashcat_ctx , " Hashfile '%s' on line %u (%s): %s " , hashes - > hashfile , line_num , tmp_line_buf , strparser ( parser_status_postprocess ) ) ;
}
hcfree ( tmp_line_buf ) ;
continue ;
}
}
2017-02-13 15:46:37 +00:00
hashes_buf [ hashes_cnt ] . hash_info - > split - > split_group = line_num ;
hashes_buf [ hashes_cnt ] . hash_info - > split - > split_origin = SPLIT_ORIGIN_RIGHT ;
2016-09-16 15:01:18 +00:00
hashes_cnt + + ;
}
else
{
2018-12-14 11:22:13 +00:00
hash_t * hash = & hashes_buf [ hashes_cnt ] ;
2019-01-25 10:14:04 +00:00
int parser_status = module_ctx - > module_hash_decode ( hashconfig , hash - > digest , hash - > salt , hash - > esalt , hash - > hook_salt , hash - > hash_info , hash_buf , hash_len ) ;
2016-09-16 15:01:18 +00:00
if ( parser_status < PARSER_GLOBAL_ZERO )
{
2017-11-17 08:50:52 +00:00
char * tmp_line_buf ;
2017-11-16 11:37:31 +00:00
2017-11-17 08:50:52 +00:00
hc_asprintf ( & tmp_line_buf , " %s " , line_buf ) ;
2017-11-16 11:37:31 +00:00
compress_terminal_line_length ( tmp_line_buf , 38 , 32 ) ;
2021-04-28 07:48:33 +00:00
if ( user_options - > machine_readable = = true )
{
event_log_warning ( hashcat_ctx , " %s:%u:%s:%s " , hashes - > hashfile , line_num , tmp_line_buf , strparser ( parser_status ) ) ;
}
else
{
event_log_warning ( hashcat_ctx , " Hashfile '%s' on line %u (%s): %s " , hashes - > hashfile , line_num , tmp_line_buf , strparser ( parser_status ) ) ;
2021-04-04 13:11:07 +00:00
}
2017-11-16 11:37:31 +00:00
hcfree ( tmp_line_buf ) ;
2016-09-16 15:01:18 +00:00
continue ;
}
2021-11-28 12:58:27 +00:00
if ( module_ctx - > module_hash_decode_postprocess ! = MODULE_DEFAULT )
{
int parser_status_postprocess = module_ctx - > module_hash_decode_postprocess ( hashconfig , hash - > digest , hash - > salt , hash - > esalt , hash - > hook_salt , hash - > hash_info , user_options , user_options_extra ) ;
if ( parser_status_postprocess < PARSER_GLOBAL_ZERO )
{
char * tmp_line_buf ;
hc_asprintf ( & tmp_line_buf , " %s " , line_buf ) ;
compress_terminal_line_length ( tmp_line_buf , 38 , 32 ) ;
if ( user_options - > machine_readable = = true )
{
event_log_warning ( hashcat_ctx , " %s:%u:%s:%s " , hashes - > hashfile , line_num , tmp_line_buf , strparser ( parser_status_postprocess ) ) ;
}
else
{
event_log_warning ( hashcat_ctx , " Hashfile '%s' on line %u (%s): %s " , hashes - > hashfile , line_num , tmp_line_buf , strparser ( parser_status_postprocess ) ) ;
}
hcfree ( tmp_line_buf ) ;
continue ;
}
}
2017-02-13 15:46:37 +00:00
hashes_buf [ hashes_cnt ] . hash_info - > split - > split_group = line_num ;
hashes_buf [ hashes_cnt ] . hash_info - > split - > split_origin = SPLIT_ORIGIN_NONE ;
2016-09-16 15:01:18 +00:00
hashes_cnt + + ;
}
}
else
{
2018-12-14 11:22:13 +00:00
hash_t * hash = & hashes_buf [ hashes_cnt ] ;
2019-01-25 10:14:04 +00:00
int parser_status = module_ctx - > module_hash_decode ( hashconfig , hash - > digest , hash - > salt , hash - > esalt , hash - > hook_salt , hash - > hash_info , hash_buf , hash_len ) ;
2016-09-16 15:01:18 +00:00
if ( parser_status < PARSER_GLOBAL_ZERO )
{
2017-11-17 08:50:52 +00:00
char * tmp_line_buf ;
2017-11-16 11:37:31 +00:00
2017-11-17 08:50:52 +00:00
hc_asprintf ( & tmp_line_buf , " %s " , line_buf ) ;
2017-11-16 11:37:31 +00:00
compress_terminal_line_length ( tmp_line_buf , 38 , 32 ) ;
2021-04-28 07:48:33 +00:00
if ( user_options - > machine_readable = = true )
{
event_log_warning ( hashcat_ctx , " %s:%u:%s:%s " , hashes - > hashfile , line_num , tmp_line_buf , strparser ( parser_status ) ) ;
}
else
{
event_log_warning ( hashcat_ctx , " Hashfile '%s' on line %u (%s): %s " , hashes - > hashfile , line_num , tmp_line_buf , strparser ( parser_status ) ) ;
2021-04-04 13:11:07 +00:00
}
2017-11-16 11:37:31 +00:00
hcfree ( tmp_line_buf ) ;
2016-09-16 15:01:18 +00:00
2022-05-04 12:26:53 +00:00
if ( parser_status = = PARSER_TOKEN_LENGTH )
{
hashes - > parser_token_length_cnt + + ;
}
2016-09-16 15:01:18 +00:00
continue ;
}
2021-11-28 12:58:27 +00:00
if ( module_ctx - > module_hash_decode_postprocess ! = MODULE_DEFAULT )
{
int parser_status_postprocess = module_ctx - > module_hash_decode_postprocess ( hashconfig , hash - > digest , hash - > salt , hash - > esalt , hash - > hook_salt , hash - > hash_info , user_options , user_options_extra ) ;
if ( parser_status_postprocess < PARSER_GLOBAL_ZERO )
{
char * tmp_line_buf ;
hc_asprintf ( & tmp_line_buf , " %s " , line_buf ) ;
compress_terminal_line_length ( tmp_line_buf , 38 , 32 ) ;
if ( user_options - > machine_readable = = true )
{
event_log_warning ( hashcat_ctx , " %s:%u:%s:%s " , hashes - > hashfile , line_num , tmp_line_buf , strparser ( parser_status_postprocess ) ) ;
}
else
{
event_log_warning ( hashcat_ctx , " Hashfile '%s' on line %u (%s): %s " , hashes - > hashfile , line_num , tmp_line_buf , strparser ( parser_status_postprocess ) ) ;
}
hcfree ( tmp_line_buf ) ;
2022-05-04 12:26:53 +00:00
if ( parser_status_postprocess = = PARSER_TOKEN_LENGTH )
{
hashes - > parser_token_length_cnt + + ;
}
2021-11-28 12:58:27 +00:00
continue ;
}
}
2016-09-16 15:01:18 +00:00
hashes_cnt + + ;
}
2016-10-23 12:49:40 +00:00
2017-12-10 00:40:45 +00:00
time ( & now ) ;
2016-10-23 12:49:40 +00:00
if ( ( now - prev ) = = 0 ) continue ;
2017-12-10 00:40:45 +00:00
time ( & prev ) ;
2016-10-23 12:49:40 +00:00
hashlist_parse_t hashlist_parse ;
hashlist_parse . hashes_cnt = hashes_cnt ;
hashlist_parse . hashes_avail = hashes_avail ;
2016-11-02 23:07:01 +00:00
EVENT_DATA ( EVENT_HASHLIST_PARSE_HASH , & hashlist_parse , sizeof ( hashlist_parse_t ) ) ;
2016-09-16 15:01:18 +00:00
}
2016-10-23 12:49:40 +00:00
hashlist_parse_t hashlist_parse ;
hashlist_parse . hashes_cnt = hashes_cnt ;
hashlist_parse . hashes_avail = hashes_avail ;
2016-11-02 23:07:01 +00:00
EVENT_DATA ( EVENT_HASHLIST_PARSE_HASH , & hashlist_parse , sizeof ( hashlist_parse_t ) ) ;
2016-10-23 12:49:40 +00:00
2016-10-10 09:03:11 +00:00
hcfree ( line_buf ) ;
2016-09-16 15:01:18 +00:00
2019-06-26 17:06:46 +00:00
hc_fclose ( & fp ) ;
2016-09-16 15:01:18 +00:00
}
2019-02-25 10:20:22 +00:00
else if ( hashlist_mode = = HL_MODE_FILE_BINARY )
{
char * input_buf = user_options_extra - > hc_hash ;
size_t input_len = strlen ( input_buf ) ;
if ( hashconfig - > opts_type & OPTS_TYPE_HASH_COPY )
{
hashinfo_t * hash_info_tmp = hashes_buf [ hashes_cnt ] . hash_info ;
hash_info_tmp - > orighash = hcstrdup ( input_buf ) ;
}
if ( hashconfig - > is_salted = = true )
{
memset ( hashes_buf [ 0 ] . salt , 0 , sizeof ( salt_t ) ) ;
}
if ( hashconfig - > esalt_size > 0 )
{
memset ( hashes_buf [ 0 ] . esalt , 0 , hashconfig - > esalt_size ) ;
}
if ( hashconfig - > hook_salt_size > 0 )
{
memset ( hashes_buf [ 0 ] . hook_salt , 0 , hashconfig - > hook_salt_size ) ;
}
if ( module_ctx - > module_hash_binary_parse ! = MODULE_DEFAULT )
{
const int hashes_parsed = module_ctx - > module_hash_binary_parse ( hashconfig , user_options , user_options_extra , hashes ) ;
if ( hashes_parsed > 0 )
{
hashes_cnt = hashes_parsed ;
}
Allow module_hash_binary_parse to report a fatal error
If module_hash_binary_parse is completely unable to successfully parse out
any hashes, up until now the output has been
```
Hashfile 'foo': Success
```
which is less than helpful.
This patch allows (but does not require) m_h_binary_parse to report a useful
error response, by returning a negative value. Modules which continue to
return '0 hashes' will get the same less-than-useful behaviour they always
hace.
I've also modified the LUKS module to report a useful error, as a proof of
concept.
Further expansions on this could include:
* Applying similar behaviour to module_hash_binary_count, so it too can
report errors when trying to count hashes. This would require more
co-ordinated change, because m_h_binary_count already uses -1 to indicate
a system error.
* Allow and encourage modules to print their own errors and warnings during
parsing. This would allow for situations where a single hash in a
multi-hash file could be reported as malformed, without having to fail the
whole parse. However, implementing this would, I expect, require modules
to have access to `hashcat_ctx`, which... yeah. Not so straightforward.
2020-04-23 01:41:27 +00:00
else if ( hashes_parsed = = 0 )
2020-05-27 13:23:02 +00:00
{
event_log_warning ( hashcat_ctx , " No hashes loaded. " ) ;
}
else if ( hashes_parsed = = PARSER_HAVE_ERRNO )
2019-02-25 10:20:22 +00:00
{
event_log_warning ( hashcat_ctx , " Hashfile '%s': %s " , hashes - > hashfile , strerror ( errno ) ) ;
}
Allow module_hash_binary_parse to report a fatal error
If module_hash_binary_parse is completely unable to successfully parse out
any hashes, up until now the output has been
```
Hashfile 'foo': Success
```
which is less than helpful.
This patch allows (but does not require) m_h_binary_parse to report a useful
error response, by returning a negative value. Modules which continue to
return '0 hashes' will get the same less-than-useful behaviour they always
hace.
I've also modified the LUKS module to report a useful error, as a proof of
concept.
Further expansions on this could include:
* Applying similar behaviour to module_hash_binary_count, so it too can
report errors when trying to count hashes. This would require more
co-ordinated change, because m_h_binary_count already uses -1 to indicate
a system error.
* Allow and encourage modules to print their own errors and warnings during
parsing. This would allow for situations where a single hash in a
multi-hash file could be reported as malformed, without having to fail the
whole parse. However, implementing this would, I expect, require modules
to have access to `hashcat_ctx`, which... yeah. Not so straightforward.
2020-04-23 01:41:27 +00:00
else
{
event_log_warning ( hashcat_ctx , " Hashfile '%s': %s " , hashes - > hashfile , strparser ( hashes_parsed ) ) ;
}
2019-02-25 10:20:22 +00:00
}
else
{
hash_t * hash = & hashes_buf [ hashes_cnt ] ;
int parser_status = module_ctx - > module_hash_decode ( hashconfig , hash - > digest , hash - > salt , hash - > esalt , hash - > hook_salt , hash - > hash_info , input_buf , input_len ) ;
if ( parser_status = = PARSER_OK )
{
2021-11-28 12:58:27 +00:00
if ( module_ctx - > module_hash_decode_postprocess ! = MODULE_DEFAULT )
{
parser_status = module_ctx - > module_hash_decode_postprocess ( hashconfig , hash - > digest , hash - > salt , hash - > esalt , hash - > hook_salt , hash - > hash_info , user_options , user_options_extra ) ;
if ( parser_status = = PARSER_OK )
{
// nothing to do
}
else
{
event_log_warning ( hashcat_ctx , " Hash '%s': %s " , input_buf , strparser ( parser_status ) ) ;
}
}
2019-02-25 10:20:22 +00:00
hashes_cnt + + ;
}
else
{
event_log_warning ( hashcat_ctx , " Hash '%s': %s " , input_buf , strparser ( parser_status ) ) ;
}
2022-05-04 12:26:53 +00:00
if ( parser_status = = PARSER_TOKEN_LENGTH )
{
hashes - > parser_token_length_cnt + + ;
}
2019-02-25 10:20:22 +00:00
}
}
2016-09-16 15:01:18 +00:00
}
hashes - > hashes_cnt = hashes_cnt ;
2016-10-06 15:26:15 +00:00
if ( hashes_cnt )
2016-09-16 15:31:31 +00:00
{
2016-10-23 12:49:40 +00:00
EVENT ( EVENT_HASHLIST_SORT_HASH_PRE ) ;
2016-10-06 15:26:15 +00:00
2017-09-16 20:33:04 +00:00
if ( hashconfig - > is_salted = = true )
2016-10-06 15:26:15 +00:00
{
hc_qsort_r ( hashes_buf , hashes_cnt , sizeof ( hash_t ) , sort_by_hash , ( void * ) hashconfig ) ;
}
else
{
hc_qsort_r ( hashes_buf , hashes_cnt , sizeof ( hash_t ) , sort_by_hash_no_salt , ( void * ) hashconfig ) ;
}
2016-10-11 09:56:40 +00:00
2016-10-23 12:49:40 +00:00
EVENT ( EVENT_HASHLIST_SORT_HASH_POST ) ;
2016-09-16 15:31:31 +00:00
}
2019-01-08 14:55:11 +00:00
if ( hashconfig - > opts_type & OPTS_TYPE_HASH_SPLIT )
2017-02-13 15:46:37 +00:00
{
// update split split_neighbor after sorting
// see https://github.com/hashcat/hashcat/issues/1034 for good examples for testing
for ( u32 i = 0 ; i < hashes_cnt ; i + + )
{
split_t * split1 = hashes_buf [ i ] . hash_info - > split ;
if ( split1 - > split_origin ! = SPLIT_ORIGIN_LEFT ) continue ;
for ( u32 j = 0 ; j < hashes_cnt ; j + + )
{
split_t * split2 = hashes_buf [ j ] . hash_info - > split ;
if ( split2 - > split_origin ! = SPLIT_ORIGIN_RIGHT ) continue ;
if ( split1 - > split_group ! = split2 - > split_group ) continue ;
split1 - > split_neighbor = j ;
split2 - > split_neighbor = i ;
break ;
}
}
}
2022-05-04 12:26:53 +00:00
if ( hashes - > parser_token_length_cnt > 0 )
{
event_log_advice ( hashcat_ctx , NULL ) ; // we can guarantee that the previous line was not an empty line
2022-07-09 10:22:39 +00:00
event_log_advice ( hashcat_ctx , " * Token length exception: %u/%u hashes " , hashes - > parser_token_length_cnt , hashes - > parser_token_length_cnt + hashes - > hashes_cnt ) ;
2022-05-04 12:26:53 +00:00
event_log_advice ( hashcat_ctx , " This error happens if the wrong hash type is specified, if the hashes are " ) ;
event_log_advice ( hashcat_ctx , " malformed, or if input is otherwise not as expected (for example, if the " ) ;
event_log_advice ( hashcat_ctx , " --username option is used but no username is present) " ) ;
event_log_advice ( hashcat_ctx , NULL ) ;
}
2016-09-16 15:01:18 +00:00
return 0 ;
}
2016-10-06 08:55:14 +00:00
int hashes_init_stage2 ( hashcat_ctx_t * hashcat_ctx )
2016-09-16 15:01:18 +00:00
{
2019-04-03 19:53:34 +00:00
const hashconfig_t * hashconfig = hashcat_ctx - > hashconfig ;
hashes_t * hashes = hashcat_ctx - > hashes ;
const user_options_t * user_options = hashcat_ctx - > user_options ;
2016-10-06 08:55:14 +00:00
2016-09-16 15:01:18 +00:00
hash_t * hashes_buf = hashes - > hashes_buf ;
2016-10-06 08:55:14 +00:00
u32 hashes_cnt = hashes - > hashes_cnt ;
2016-09-16 15:01:18 +00:00
/**
* Remove duplicates
*/
2016-10-23 12:49:40 +00:00
EVENT ( EVENT_HASHLIST_UNIQUE_HASH_PRE ) ;
2016-09-16 15:01:18 +00:00
2016-10-18 18:42:34 +00:00
u32 hashes_cnt_new = 1 ;
2016-09-16 15:01:18 +00:00
2016-10-18 18:42:34 +00:00
for ( u32 hashes_pos = 1 ; hashes_pos < hashes_cnt ; hashes_pos + + )
2016-09-16 15:01:18 +00:00
{
2018-12-20 11:59:56 +00:00
if ( hashconfig - > potfile_keep_all_hashes = = true )
2017-02-01 08:00:16 +00:00
{
// do not sort, because we need to keep all hashes in this particular case
}
2017-09-16 20:33:04 +00:00
else if ( hashconfig - > is_salted = = true )
2016-09-16 15:01:18 +00:00
{
if ( sort_by_salt ( hashes_buf [ hashes_pos ] . salt , hashes_buf [ hashes_pos - 1 ] . salt ) = = 0 )
{
2016-09-30 20:52:44 +00:00
if ( sort_by_digest_p0p1 ( hashes_buf [ hashes_pos ] . digest , hashes_buf [ hashes_pos - 1 ] . digest , ( void * ) hashconfig ) = = 0 ) continue ;
2016-09-16 15:01:18 +00:00
}
}
else
{
2016-09-30 20:52:44 +00:00
if ( sort_by_digest_p0p1 ( hashes_buf [ hashes_pos ] . digest , hashes_buf [ hashes_pos - 1 ] . digest , ( void * ) hashconfig ) = = 0 ) continue ;
2016-09-16 15:01:18 +00:00
}
2016-10-18 18:42:34 +00:00
hash_t tmp ;
2016-09-16 15:01:18 +00:00
2016-10-18 18:42:34 +00:00
memcpy ( & tmp , & hashes_buf [ hashes_pos ] , sizeof ( hash_t ) ) ;
memcpy ( & hashes_buf [ hashes_cnt_new ] , & tmp , sizeof ( hash_t ) ) ;
hashes_cnt_new + + ;
2016-09-16 15:01:18 +00:00
}
2016-10-18 18:42:34 +00:00
for ( u32 i = hashes_cnt_new ; i < hashes - > hashes_cnt ; i + + )
{
memset ( & hashes_buf [ i ] , 0 , sizeof ( hash_t ) ) ;
}
hashes_cnt = hashes_cnt_new ;
2016-09-16 15:01:18 +00:00
hashes - > hashes_cnt = hashes_cnt ;
2016-10-23 12:49:40 +00:00
EVENT ( EVENT_HASHLIST_UNIQUE_HASH_POST ) ;
2016-09-16 15:01:18 +00:00
/**
* Now generate all the buffers required for later
*/
2017-11-05 08:52:29 +00:00
void * digests_buf_new = hccalloc ( hashes_cnt , hashconfig - > dgst_size ) ;
2017-01-24 14:23:48 +00:00
salt_t * salts_buf_new = NULL ;
void * esalts_buf_new = NULL ;
void * hook_salts_buf_new = NULL ;
2016-09-16 15:01:18 +00:00
2017-09-16 20:33:04 +00:00
if ( hashconfig - > is_salted = = true )
2016-09-16 15:01:18 +00:00
{
2016-11-20 21:54:52 +00:00
salts_buf_new = ( salt_t * ) hccalloc ( hashes_cnt , sizeof ( salt_t ) ) ;
2016-09-16 15:01:18 +00:00
}
else
{
2016-11-20 21:54:52 +00:00
salts_buf_new = ( salt_t * ) hccalloc ( 1 , sizeof ( salt_t ) ) ;
2016-09-16 15:01:18 +00:00
}
2017-09-16 20:33:04 +00:00
if ( hashconfig - > esalt_size > 0 )
2016-11-12 14:27:11 +00:00
{
2017-11-05 08:52:29 +00:00
esalts_buf_new = hccalloc ( hashes_cnt , hashconfig - > esalt_size ) ;
2016-11-12 14:27:11 +00:00
}
2017-09-16 20:33:04 +00:00
if ( hashconfig - > hook_salt_size > 0 )
2017-01-24 14:23:48 +00:00
{
2017-11-05 08:52:29 +00:00
hook_salts_buf_new = hccalloc ( hashes_cnt , hashconfig - > hook_salt_size ) ;
2017-01-24 14:23:48 +00:00
}
2016-10-23 12:49:40 +00:00
EVENT ( EVENT_HASHLIST_SORT_SALT_PRE ) ;
2016-09-16 15:01:18 +00:00
2016-10-04 04:35:49 +00:00
u32 digests_cnt = hashes_cnt ;
u32 digests_done = 0 ;
2016-09-16 15:01:18 +00:00
2022-08-19 10:02:21 +00:00
u32 * digests_shown = ( u32 * ) hccalloc ( digests_cnt , sizeof ( u32 ) ) ;
2016-09-16 15:01:18 +00:00
2016-10-04 04:35:49 +00:00
u32 salts_cnt = 0 ;
u32 salts_done = 0 ;
2016-09-16 15:01:18 +00:00
hashinfo_t * * hash_info = NULL ;
2017-02-13 15:46:37 +00:00
if ( ( user_options - > username = = true ) | | ( hashconfig - > opts_type & OPTS_TYPE_HASH_COPY ) | | ( hashconfig - > opts_type & OPTS_TYPE_HASH_SPLIT ) )
2016-09-16 15:01:18 +00:00
{
2016-11-20 21:54:52 +00:00
hash_info = ( hashinfo_t * * ) hccalloc ( hashes_cnt , sizeof ( hashinfo_t * ) ) ;
2016-09-16 15:01:18 +00:00
}
2016-11-20 21:54:52 +00:00
u32 * salts_shown = ( u32 * ) hccalloc ( digests_cnt , sizeof ( u32 ) ) ;
2016-09-16 15:01:18 +00:00
salt_t * salt_buf ;
{
// copied from inner loop
salt_buf = & salts_buf_new [ salts_cnt ] ;
memcpy ( salt_buf , hashes_buf [ 0 ] . salt , sizeof ( salt_t ) ) ;
2016-10-18 18:42:34 +00:00
hashes_buf [ 0 ] . salt = salt_buf ;
2017-09-16 20:33:04 +00:00
if ( hashconfig - > hook_salt_size > 0 )
2017-01-24 14:23:48 +00:00
{
char * hook_salts_buf_new_ptr = ( ( char * ) hook_salts_buf_new ) + ( salts_cnt * hashconfig - > hook_salt_size ) ;
memcpy ( hook_salts_buf_new_ptr , hashes_buf [ 0 ] . hook_salt , hashconfig - > hook_salt_size ) ;
hashes_buf [ 0 ] . hook_salt = hook_salts_buf_new_ptr ;
}
2016-09-16 15:01:18 +00:00
salt_buf - > digests_cnt = 0 ;
salt_buf - > digests_done = 0 ;
salt_buf - > digests_offset = 0 ;
salts_cnt + + ;
}
2016-10-18 18:42:34 +00:00
salt_buf - > digests_cnt + + ;
2016-09-16 15:01:18 +00:00
2016-10-18 18:42:34 +00:00
char * digests_buf_new_ptr = ( ( char * ) digests_buf_new ) + ( 0 * hashconfig - > dgst_size ) ;
2016-09-16 15:01:18 +00:00
2016-10-18 18:42:34 +00:00
memcpy ( digests_buf_new_ptr , hashes_buf [ 0 ] . digest , hashconfig - > dgst_size ) ;
2016-09-16 15:01:18 +00:00
2016-10-18 18:42:34 +00:00
hashes_buf [ 0 ] . digest = digests_buf_new_ptr ;
2016-09-16 15:01:18 +00:00
2017-09-16 20:33:04 +00:00
if ( hashconfig - > esalt_size > 0 )
2017-03-07 08:44:58 +00:00
{
char * esalts_buf_new_ptr = ( ( char * ) esalts_buf_new ) + ( 0 * hashconfig - > esalt_size ) ;
memcpy ( esalts_buf_new_ptr , hashes_buf [ 0 ] . esalt , hashconfig - > esalt_size ) ;
hashes_buf [ 0 ] . esalt = esalts_buf_new_ptr ;
}
2017-02-13 15:46:37 +00:00
if ( ( user_options - > username = = true ) | | ( hashconfig - > opts_type & OPTS_TYPE_HASH_COPY ) | | ( hashconfig - > opts_type & OPTS_TYPE_HASH_SPLIT ) )
2016-09-16 15:01:18 +00:00
{
hash_info [ 0 ] = hashes_buf [ 0 ] . hash_info ;
}
// copy from inner loop
2016-10-04 04:35:49 +00:00
for ( u32 hashes_pos = 1 ; hashes_pos < hashes_cnt ; hashes_pos + + )
2016-09-16 15:01:18 +00:00
{
2017-09-16 20:33:04 +00:00
if ( hashconfig - > is_salted = = true )
2016-09-16 15:01:18 +00:00
{
if ( sort_by_salt ( hashes_buf [ hashes_pos ] . salt , hashes_buf [ hashes_pos - 1 ] . salt ) ! = 0 )
{
salt_buf = & salts_buf_new [ salts_cnt ] ;
memcpy ( salt_buf , hashes_buf [ hashes_pos ] . salt , sizeof ( salt_t ) ) ;
2016-10-18 18:42:34 +00:00
hashes_buf [ hashes_pos ] . salt = salt_buf ;
2017-09-16 20:33:04 +00:00
if ( hashconfig - > hook_salt_size > 0 )
2017-01-24 14:23:48 +00:00
{
char * hook_salts_buf_new_ptr = ( ( char * ) hook_salts_buf_new ) + ( salts_cnt * hashconfig - > hook_salt_size ) ;
memcpy ( hook_salts_buf_new_ptr , hashes_buf [ hashes_pos ] . hook_salt , hashconfig - > hook_salt_size ) ;
hashes_buf [ hashes_pos ] . hook_salt = hook_salts_buf_new_ptr ;
}
2016-09-16 15:01:18 +00:00
salt_buf - > digests_cnt = 0 ;
salt_buf - > digests_done = 0 ;
salt_buf - > digests_offset = hashes_pos ;
salts_cnt + + ;
}
2016-11-07 15:10:16 +00:00
hashes_buf [ hashes_pos ] . salt = salt_buf ;
2017-09-16 20:33:04 +00:00
if ( hashconfig - > hook_salt_size > 0 )
2017-01-24 14:23:48 +00:00
{
char * hook_salts_buf_new_ptr = ( ( char * ) hook_salts_buf_new ) + ( salts_cnt * hashconfig - > hook_salt_size ) ;
hashes_buf [ hashes_pos ] . hook_salt = hook_salts_buf_new_ptr ;
}
2016-09-16 15:01:18 +00:00
}
2016-10-18 18:42:34 +00:00
salt_buf - > digests_cnt + + ;
2016-09-16 15:01:18 +00:00
2016-10-18 18:42:34 +00:00
digests_buf_new_ptr = ( ( char * ) digests_buf_new ) + ( hashes_pos * hashconfig - > dgst_size ) ;
2016-09-16 15:01:18 +00:00
2016-10-18 18:42:34 +00:00
memcpy ( digests_buf_new_ptr , hashes_buf [ hashes_pos ] . digest , hashconfig - > dgst_size ) ;
2016-09-16 15:01:18 +00:00
2016-10-18 18:42:34 +00:00
hashes_buf [ hashes_pos ] . digest = digests_buf_new_ptr ;
2016-09-16 15:01:18 +00:00
2017-09-16 20:33:04 +00:00
if ( hashconfig - > esalt_size > 0 )
2017-03-07 08:44:58 +00:00
{
char * esalts_buf_new_ptr = ( ( char * ) esalts_buf_new ) + ( hashes_pos * hashconfig - > esalt_size ) ;
memcpy ( esalts_buf_new_ptr , hashes_buf [ hashes_pos ] . esalt , hashconfig - > esalt_size ) ;
hashes_buf [ hashes_pos ] . esalt = esalts_buf_new_ptr ;
}
2017-02-13 15:46:37 +00:00
if ( ( user_options - > username = = true ) | | ( hashconfig - > opts_type & OPTS_TYPE_HASH_COPY ) | | ( hashconfig - > opts_type & OPTS_TYPE_HASH_SPLIT ) )
2016-09-16 15:01:18 +00:00
{
hash_info [ hashes_pos ] = hashes_buf [ hashes_pos ] . hash_info ;
}
}
2016-10-23 12:49:40 +00:00
EVENT ( EVENT_HASHLIST_SORT_SALT_POST ) ;
2016-10-10 09:03:11 +00:00
hcfree ( hashes - > digests_buf ) ;
hcfree ( hashes - > salts_buf ) ;
hcfree ( hashes - > esalts_buf ) ;
2017-01-24 14:23:48 +00:00
hcfree ( hashes - > hook_salts_buf ) ;
2016-09-16 15:01:18 +00:00
2017-01-24 14:23:48 +00:00
hashes - > digests_cnt = digests_cnt ;
hashes - > digests_done = digests_done ;
hashes - > digests_buf = digests_buf_new ;
hashes - > digests_shown = digests_shown ;
2016-09-16 15:01:18 +00:00
2017-01-24 14:23:48 +00:00
hashes - > salts_cnt = salts_cnt ;
hashes - > salts_done = salts_done ;
hashes - > salts_buf = salts_buf_new ;
hashes - > salts_shown = salts_shown ;
2016-09-16 15:01:18 +00:00
2017-01-24 14:23:48 +00:00
hashes - > esalts_buf = esalts_buf_new ;
hashes - > hook_salts_buf = hook_salts_buf_new ;
2016-09-16 15:01:18 +00:00
2017-01-24 14:23:48 +00:00
hashes - > hash_info = hash_info ;
2016-09-16 15:01:18 +00:00
return 0 ;
}
2016-10-06 08:55:14 +00:00
int hashes_init_stage3 ( hashcat_ctx_t * hashcat_ctx )
2016-10-18 18:42:34 +00:00
{
hashes_t * hashes = hashcat_ctx - > hashes ;
2022-08-19 10:02:21 +00:00
u32 digests_done = hashes - > digests_done ;
u32 digests_done_zero = hashes - > digests_done_zero ;
u32 digests_done_pot = hashes - > digests_done_pot ;
u32 * digests_shown = hashes - > digests_shown ;
2016-10-18 18:42:34 +00:00
2022-08-19 10:02:21 +00:00
u32 salts_cnt = hashes - > salts_cnt ;
u32 salts_done = hashes - > salts_done ;
u32 * salts_shown = hashes - > salts_shown ;
2016-10-18 18:42:34 +00:00
2022-08-19 10:02:21 +00:00
hash_t * hashes_buf = hashes - > hashes_buf ;
salt_t * salts_buf = hashes - > salts_buf ;
2016-10-18 18:42:34 +00:00
for ( u32 salt_idx = 0 ; salt_idx < salts_cnt ; salt_idx + + )
{
salt_t * salt_buf = salts_buf + salt_idx ;
u32 digests_cnt = salt_buf - > digests_cnt ;
for ( u32 digest_idx = 0 ; digest_idx < digests_cnt ; digest_idx + + )
{
const u32 hashes_idx = salt_buf - > digests_offset + digest_idx ;
2022-08-19 10:02:21 +00:00
if ( hashes_buf [ hashes_idx ] . cracked_pot = = 1 )
{
digests_shown [ hashes_idx ] = 1 ;
digests_done + + ;
digests_done_pot + + ;
salt_buf - > digests_done + + ;
}
if ( hashes_buf [ hashes_idx ] . cracked_zero = = 1 )
2016-10-18 18:42:34 +00:00
{
digests_shown [ hashes_idx ] = 1 ;
digests_done + + ;
2022-08-19 10:02:21 +00:00
digests_done_zero + + ;
2016-10-18 18:42:34 +00:00
salt_buf - > digests_done + + ;
}
}
if ( salt_buf - > digests_done = = salt_buf - > digests_cnt )
{
salts_shown [ salt_idx ] = 1 ;
salts_done + + ;
}
if ( salts_done = = salts_cnt ) mycracked ( hashcat_ctx ) ;
}
2022-08-19 10:02:21 +00:00
hashes - > digests_done = digests_done ;
hashes - > digests_done_zero = digests_done_zero ;
hashes - > digests_done_pot = digests_done_pot ;
2016-10-18 18:42:34 +00:00
2022-08-19 10:02:21 +00:00
hashes - > salts_done = salts_done ;
2016-10-18 18:42:34 +00:00
return 0 ;
}
int hashes_init_stage4 ( hashcat_ctx_t * hashcat_ctx )
2016-09-23 19:41:05 +00:00
{
2019-01-28 13:05:58 +00:00
hashconfig_t * hashconfig = hashcat_ctx - > hashconfig ;
hashes_t * hashes = hashcat_ctx - > hashes ;
module_ctx_t * module_ctx = hashcat_ctx - > module_ctx ;
user_options_t * user_options = hashcat_ctx - > user_options ;
user_options_extra_t * user_options_extra = hashcat_ctx - > user_options_extra ;
2016-10-06 08:55:14 +00:00
2016-09-23 19:41:05 +00:00
if ( hashes - > salts_cnt = = 1 )
hashconfig - > opti_type | = OPTI_TYPE_SINGLE_SALT ;
if ( hashes - > digests_cnt = = 1 )
hashconfig - > opti_type | = OPTI_TYPE_SINGLE_HASH ;
if ( hashconfig - > attack_exec = = ATTACK_EXEC_INSIDE_KERNEL )
hashconfig - > opti_type | = OPTI_TYPE_NOT_ITERATED ;
if ( user_options - > attack_mode = = ATTACK_MODE_BF )
hashconfig - > opti_type | = OPTI_TYPE_BRUTE_FORCE ;
if ( hashconfig - > opti_type & OPTI_TYPE_BRUTE_FORCE )
{
if ( hashconfig - > opti_type & OPTI_TYPE_SINGLE_HASH )
{
if ( hashconfig - > opti_type & OPTI_TYPE_APPENDED_SALT )
{
if ( hashconfig - > opts_type & OPTS_TYPE_ST_ADD80 )
{
hashconfig - > opts_type & = ~ OPTS_TYPE_ST_ADD80 ;
hashconfig - > opts_type | = OPTS_TYPE_PT_ADD80 ;
}
if ( hashconfig - > opts_type & OPTS_TYPE_ST_ADDBITS14 )
{
hashconfig - > opts_type & = ~ OPTS_TYPE_ST_ADDBITS14 ;
hashconfig - > opts_type | = OPTS_TYPE_PT_ADDBITS14 ;
}
if ( hashconfig - > opts_type & OPTS_TYPE_ST_ADDBITS15 )
{
hashconfig - > opts_type & = ~ OPTS_TYPE_ST_ADDBITS15 ;
hashconfig - > opts_type | = OPTS_TYPE_PT_ADDBITS15 ;
}
}
}
}
2023-03-15 19:45:56 +00:00
// https://github.com/hashcat/hashcat/issues/3641
if ( ( hashconfig - > opts_type & OPTS_TYPE_DEEP_COMP_KERNEL ) = = 0 )
{
if ( hashconfig - > attack_exec = = ATTACK_EXEC_OUTSIDE_KERNEL )
{
if ( hashes - > digests_cnt ! = hashes - > salts_cnt )
{
event_log_error ( hashcat_ctx , " This hash-mode plugin cannot crack multiple hashes with the same salt, please select one of the hashes. " ) ;
return - 1 ;
}
}
}
2020-09-29 13:56:32 +00:00
// test iteration count in association attack
if ( user_options - > attack_mode = = ATTACK_MODE_ASSOCIATION )
{
salt_t * salts_buf = hashes - > salts_buf ;
for ( u32 salt_idx = 1 ; salt_idx < hashes - > salts_cnt ; salt_idx + + )
{
if ( salts_buf [ salt_idx - 1 ] . salt_iter ! = salts_buf [ salt_idx ] . salt_iter )
{
event_log_error ( hashcat_ctx , " Mixed iteration counts are not supported in association attack-mode. " ) ;
return - 1 ;
}
}
}
2019-01-28 13:05:58 +00:00
// time to update extra_tmp_size which is tmp_size value based on hash configuration
if ( module_ctx - > module_extra_tmp_size ! = MODULE_DEFAULT )
{
const u64 extra_tmp_size = module_ctx - > module_extra_tmp_size ( hashconfig , user_options , user_options_extra , hashes ) ;
if ( extra_tmp_size = = ( u64 ) - 1 )
{
event_log_error ( hashcat_ctx , " Mixed hash settings are not supported. " ) ;
return - 1 ;
}
2021-08-13 10:08:47 +00:00
hashconfig - > tmp_size = extra_tmp_size ;
2019-01-28 13:05:58 +00:00
}
2016-10-19 09:55:43 +00:00
// at this point we no longer need hash_t* structure
hash_t * hashes_buf = hashes - > hashes_buf ;
hcfree ( hashes_buf ) ;
hashes - > hashes_cnt = 0 ;
hashes - > hashes_buf = NULL ;
2016-10-30 21:22:26 +00:00
// starting from here, we should allocate some scratch buffer for later use
2016-11-20 21:54:52 +00:00
u8 * out_buf = ( u8 * ) hcmalloc ( HCBUFSIZ_LARGE ) ;
2016-10-30 21:22:26 +00:00
hashes - > out_buf = out_buf ;
// we need two buffers in parallel
2016-11-20 21:54:52 +00:00
u8 * tmp_buf = ( u8 * ) hcmalloc ( HCBUFSIZ_LARGE ) ;
2016-10-30 21:22:26 +00:00
hashes - > tmp_buf = tmp_buf ;
2018-10-28 15:47:13 +00:00
// brain session
# ifdef WITH_BRAIN
2018-11-03 12:15:23 +00:00
if ( user_options - > brain_client = = true )
{
const u32 brain_session = brain_compute_session ( hashcat_ctx ) ;
2018-10-28 15:47:13 +00:00
2018-11-03 12:15:23 +00:00
user_options - > brain_session = brain_session ;
}
2018-10-28 15:47:13 +00:00
# endif
2016-09-23 19:41:05 +00:00
return 0 ;
}
2017-06-13 17:07:08 +00:00
int hashes_init_selftest ( hashcat_ctx_t * hashcat_ctx )
{
2017-06-14 12:05:50 +00:00
folder_config_t * folder_config = hashcat_ctx - > folder_config ;
hashconfig_t * hashconfig = hashcat_ctx - > hashconfig ;
hashes_t * hashes = hashcat_ctx - > hashes ;
2018-12-14 11:22:13 +00:00
module_ctx_t * module_ctx = hashcat_ctx - > module_ctx ;
2017-09-06 20:14:06 +00:00
user_options_t * user_options = hashcat_ctx - > user_options ;
2017-06-13 17:07:08 +00:00
if ( hashconfig - > st_hash = = NULL ) return 0 ;
2017-06-14 10:07:33 +00:00
void * st_digests_buf = NULL ;
salt_t * st_salts_buf = NULL ;
void * st_esalts_buf = NULL ;
void * st_hook_salts_buf = NULL ;
2017-06-13 17:07:08 +00:00
2017-11-05 08:52:29 +00:00
st_digests_buf = hccalloc ( 1 , hashconfig - > dgst_size ) ;
2017-06-13 17:07:08 +00:00
st_salts_buf = ( salt_t * ) hccalloc ( 1 , sizeof ( salt_t ) ) ;
2017-09-16 20:33:04 +00:00
if ( hashconfig - > esalt_size > 0 )
2017-06-13 17:07:08 +00:00
{
2017-11-05 08:52:29 +00:00
st_esalts_buf = hccalloc ( 1 , hashconfig - > esalt_size ) ;
2017-06-13 17:07:08 +00:00
}
2017-09-16 20:33:04 +00:00
if ( hashconfig - > hook_salt_size > 0 )
2017-06-14 10:07:33 +00:00
{
2017-11-05 08:52:29 +00:00
st_hook_salts_buf = hccalloc ( 1 , hashconfig - > hook_salt_size ) ;
2017-06-14 10:07:33 +00:00
}
2017-06-13 17:07:08 +00:00
hash_t hash ;
hash . digest = st_digests_buf ;
hash . salt = st_salts_buf ;
hash . esalt = st_esalts_buf ;
2017-06-14 10:07:33 +00:00
hash . hook_salt = st_hook_salts_buf ;
2017-06-13 17:07:08 +00:00
hash . cracked = 0 ;
hash . hash_info = NULL ;
hash . pw_buf = NULL ;
hash . pw_len = 0 ;
2017-06-14 12:05:50 +00:00
int parser_status ;
2019-01-07 09:05:50 +00:00
if ( module_ctx - > module_hash_init_selftest ! = MODULE_DEFAULT )
2017-06-14 12:05:50 +00:00
{
2019-01-07 09:05:50 +00:00
parser_status = module_ctx - > module_hash_init_selftest ( hashconfig , & hash ) ;
2017-06-14 12:05:50 +00:00
}
2019-01-07 09:05:50 +00:00
else
2017-06-14 12:05:50 +00:00
{
2019-01-07 09:05:50 +00:00
if ( hashconfig - > opts_type & OPTS_TYPE_BINARY_HASHFILE )
{
2021-04-04 09:38:02 +00:00
if ( hashconfig - > opts_type & OPTS_TYPE_BINARY_HASHFILE_OPTIONAL )
{
parser_status = module_ctx - > module_hash_decode ( hashconfig , hash . digest , hash . salt , hash . esalt , hash . hook_salt , hash . hash_info , hashconfig - > st_hash , strlen ( hashconfig - > st_hash ) ) ;
}
else
{
char * tmpfile_bin ;
2017-06-14 12:05:50 +00:00
2021-04-04 09:38:02 +00:00
hc_asprintf ( & tmpfile_bin , " %s/selftest.hash " , folder_config - > session_dir ) ;
2017-06-14 12:05:50 +00:00
2021-04-04 09:38:02 +00:00
HCFILE fp ;
2019-06-21 19:56:38 +00:00
2021-04-04 09:38:02 +00:00
hc_fopen ( & fp , tmpfile_bin , " wb " ) ;
2019-06-28 15:58:08 +00:00
2021-04-04 09:38:02 +00:00
const size_t st_hash_len = strlen ( hashconfig - > st_hash ) ;
2017-06-14 12:05:50 +00:00
2021-04-04 09:38:02 +00:00
for ( size_t i = 0 ; i < st_hash_len ; i + = 2 )
{
const u8 c = hex_to_u8 ( ( const u8 * ) hashconfig - > st_hash + i ) ;
2017-06-14 12:05:50 +00:00
2021-04-04 09:38:02 +00:00
hc_fputc ( c , & fp ) ;
}
2017-06-14 12:05:50 +00:00
2021-04-04 09:38:02 +00:00
hc_fclose ( & fp ) ;
2017-06-14 12:05:50 +00:00
2021-04-04 09:38:02 +00:00
parser_status = module_ctx - > module_hash_decode ( hashconfig , hash . digest , hash . salt , hash . esalt , hash . hook_salt , hash . hash_info , tmpfile_bin , strlen ( tmpfile_bin ) ) ;
2017-06-14 12:05:50 +00:00
2021-04-04 09:38:02 +00:00
unlink ( tmpfile_bin ) ;
2017-06-14 12:05:50 +00:00
2021-04-04 09:38:02 +00:00
hcfree ( tmpfile_bin ) ;
}
2019-01-07 09:05:50 +00:00
}
else
{
hashconfig_t * hashconfig_st = ( hashconfig_t * ) hcmalloc ( sizeof ( hashconfig_t ) ) ;
2017-09-06 20:14:06 +00:00
2019-01-07 09:05:50 +00:00
memcpy ( hashconfig_st , hashconfig , sizeof ( hashconfig_t ) ) ;
2017-09-06 20:14:06 +00:00
2021-07-22 16:54:02 +00:00
hashconfig_st - > separator = ' : ' ;
2017-09-06 20:14:06 +00:00
2019-01-07 09:05:50 +00:00
if ( user_options - > hex_salt )
2017-09-06 20:14:06 +00:00
{
2019-01-07 09:05:50 +00:00
if ( hashconfig - > salt_type = = SALT_TYPE_GENERIC )
{
// this is save as there's no hash mode that has both SALT_TYPE_GENERIC and OPTS_TYPE_ST_HEX by default
2017-09-06 20:14:06 +00:00
2019-01-07 09:05:50 +00:00
hashconfig_st - > opts_type & = ~ OPTS_TYPE_ST_HEX ;
}
2017-09-06 20:14:06 +00:00
}
2019-01-25 10:14:04 +00:00
parser_status = module_ctx - > module_hash_decode ( hashconfig_st , hash . digest , hash . salt , hash . esalt , hash . hook_salt , hash . hash_info , hashconfig - > st_hash , strlen ( hashconfig - > st_hash ) ) ;
2017-09-06 20:14:06 +00:00
2019-01-07 09:05:50 +00:00
hcfree ( hashconfig_st ) ;
}
2017-06-14 12:05:50 +00:00
}
2017-06-13 17:07:08 +00:00
if ( parser_status = = PARSER_OK )
{
// nothing to do
}
else
{
2017-06-14 12:05:50 +00:00
event_log_error ( hashcat_ctx , " Self-test hash parsing error: %s " , strparser ( parser_status ) ) ;
2017-06-13 17:07:08 +00:00
return - 1 ;
}
2017-06-14 10:07:33 +00:00
hashes - > st_digests_buf = st_digests_buf ;
hashes - > st_salts_buf = st_salts_buf ;
hashes - > st_esalts_buf = st_esalts_buf ;
hashes - > st_hook_salts_buf = st_hook_salts_buf ;
2017-06-13 17:07:08 +00:00
return 0 ;
}
2019-01-12 00:59:18 +00:00
int hashes_init_benchmark ( hashcat_ctx_t * hashcat_ctx )
{
const hashconfig_t * hashconfig = hashcat_ctx - > hashconfig ;
hashes_t * hashes = hashcat_ctx - > hashes ;
const module_ctx_t * module_ctx = hashcat_ctx - > module_ctx ;
const user_options_t * user_options = hashcat_ctx - > user_options ;
const user_options_extra_t * user_options_extra = hashcat_ctx - > user_options_extra ;
if ( user_options - > benchmark = = false ) return 0 ;
if ( hashconfig - > is_salted = = false ) return 0 ;
if ( module_ctx - > module_benchmark_salt ! = MODULE_DEFAULT )
{
salt_t * ptr = module_ctx - > module_benchmark_salt ( hashconfig , user_options , user_options_extra ) ;
memcpy ( hashes - > salts_buf , ptr , sizeof ( salt_t ) ) ;
hcfree ( ptr ) ;
}
else
{
memcpy ( hashes - > salts_buf , hashes - > st_salts_buf , sizeof ( salt_t ) ) ;
}
if ( hashconfig - > esalt_size > 0 )
{
if ( module_ctx - > module_benchmark_esalt ! = MODULE_DEFAULT )
{
void * ptr = module_ctx - > module_benchmark_esalt ( hashconfig , user_options , user_options_extra ) ;
memcpy ( hashes - > esalts_buf , ptr , hashconfig - > esalt_size ) ;
hcfree ( ptr ) ;
}
else
{
memcpy ( hashes - > esalts_buf , hashes - > st_esalts_buf , hashconfig - > esalt_size ) ;
}
}
if ( hashconfig - > hook_salt_size > 0 )
{
if ( module_ctx - > module_benchmark_hook_salt ! = MODULE_DEFAULT )
{
void * ptr = module_ctx - > module_benchmark_hook_salt ( hashconfig , user_options , user_options_extra ) ;
memcpy ( hashes - > hook_salts_buf , ptr , hashconfig - > hook_salt_size ) ;
hcfree ( ptr ) ;
}
else
{
memcpy ( hashes - > hook_salts_buf , hashes - > st_hook_salts_buf , hashconfig - > hook_salt_size ) ;
}
}
return 0 ;
}
2021-04-21 07:22:00 +00:00
int hashes_init_zerohash ( hashcat_ctx_t * hashcat_ctx )
{
const hashconfig_t * hashconfig = hashcat_ctx - > hashconfig ;
const hashes_t * hashes = hashcat_ctx - > hashes ;
const module_ctx_t * module_ctx = hashcat_ctx - > module_ctx ;
// do not use this unless really needed, for example as in LM
if ( module_ctx - > module_hash_decode_zero_hash = = MODULE_DEFAULT ) return 0 ;
hash_t * hashes_buf = hashes - > hashes_buf ;
u32 hashes_cnt = hashes - > hashes_cnt ;
2023-07-27 16:11:55 +00:00
// no solution for these special hash types (for instance because they use hashfile in output etc)
2021-04-21 07:22:00 +00:00
hash_t hash_buf ;
hash_buf . digest = hcmalloc ( hashconfig - > dgst_size ) ;
hash_buf . salt = NULL ;
hash_buf . esalt = NULL ;
hash_buf . hook_salt = NULL ;
hash_buf . cracked = 0 ;
hash_buf . hash_info = NULL ;
hash_buf . pw_buf = NULL ;
hash_buf . pw_len = 0 ;
if ( hashconfig - > is_salted = = true )
{
hash_buf . salt = ( salt_t * ) hcmalloc ( sizeof ( salt_t ) ) ;
}
if ( hashconfig - > esalt_size > 0 )
{
hash_buf . esalt = hcmalloc ( hashconfig - > esalt_size ) ;
}
if ( hashconfig - > hook_salt_size > 0 )
{
hash_buf . hook_salt = hcmalloc ( hashconfig - > hook_salt_size ) ;
}
module_ctx - > module_hash_decode_zero_hash ( hashconfig , hash_buf . digest , hash_buf . salt , hash_buf . esalt , hash_buf . hook_salt , hash_buf . hash_info ) ;
2021-09-18 12:14:28 +00:00
for ( u32 i = 0 ; i < hashes_cnt ; i + + )
2021-04-21 07:22:00 +00:00
{
2021-09-18 12:14:28 +00:00
hash_t * next = & hashes_buf [ i ] ;
2021-04-26 07:32:19 +00:00
2021-09-18 12:14:28 +00:00
int rc = sort_by_hash_no_salt ( & hash_buf , next , ( void * ) hashconfig ) ;
2021-04-26 07:32:19 +00:00
2021-09-18 12:14:28 +00:00
if ( rc = = 0 )
2021-04-26 07:32:19 +00:00
{
2021-09-18 12:14:28 +00:00
next - > pw_buf = ( char * ) hcmalloc ( 1 ) ;
next - > pw_len = 0 ;
2021-04-26 07:32:19 +00:00
2022-08-19 10:02:21 +00:00
next - > cracked_zero = 1 ;
2021-04-26 07:32:19 +00:00
2021-09-18 12:14:28 +00:00
// should we show the cracked zero hash to the user?
2021-04-26 07:32:19 +00:00
2021-09-18 12:14:28 +00:00
if ( false )
{
// digest pos
2021-04-26 07:32:19 +00:00
2021-09-18 12:14:28 +00:00
const u32 digest_pos = next - hashes_buf ;
2021-04-26 07:32:19 +00:00
2021-09-18 12:14:28 +00:00
// show the crack
2021-04-26 07:32:19 +00:00
2021-09-18 12:14:28 +00:00
u8 * out_buf = ( u8 * ) hcmalloc ( HCBUFSIZ_LARGE ) ;
2021-04-26 07:32:19 +00:00
2021-09-18 12:14:28 +00:00
int out_len = hash_encode ( hashcat_ctx - > hashconfig , hashcat_ctx - > hashes , hashcat_ctx - > module_ctx , ( char * ) out_buf , HCBUFSIZ_LARGE , 0 , digest_pos ) ;
2021-04-26 07:32:19 +00:00
2021-09-18 12:14:28 +00:00
out_buf [ out_len ] = 0 ;
2021-04-26 07:32:19 +00:00
2021-09-18 12:14:28 +00:00
// outfile, can be either to file or stdout
// if an error occurs opening the file, send to stdout as fallback
// the fp gets opened for each cracked hash so that the user can modify (move) the outfile while hashcat runs
2021-04-26 07:32:19 +00:00
2021-09-18 12:14:28 +00:00
outfile_write_open ( hashcat_ctx ) ;
2021-04-26 07:32:19 +00:00
2021-09-18 12:14:28 +00:00
const u8 * plain = ( const u8 * ) " " ;
2021-04-26 07:32:19 +00:00
2021-09-18 12:14:28 +00:00
u8 * tmp_buf = ( u8 * ) hcmalloc ( HCBUFSIZ_LARGE ) ;
2021-04-26 07:32:19 +00:00
2021-09-18 12:14:28 +00:00
tmp_buf [ 0 ] = 0 ;
2021-04-26 07:32:19 +00:00
2021-09-18 12:14:28 +00:00
const int tmp_len = outfile_write ( hashcat_ctx , ( char * ) out_buf , out_len , plain , 0 , 0 , NULL , 0 , true , ( char * ) tmp_buf ) ;
EVENT_DATA ( EVENT_CRACKER_HASH_CRACKED , tmp_buf , tmp_len ) ;
outfile_write_close ( hashcat_ctx ) ;
hcfree ( tmp_buf ) ;
hcfree ( out_buf ) ;
}
2021-04-26 07:32:19 +00:00
}
2021-04-21 07:22:00 +00:00
}
if ( hashconfig - > esalt_size > 0 )
{
hcfree ( hash_buf . esalt ) ;
}
if ( hashconfig - > hook_salt_size > 0 )
{
hcfree ( hash_buf . hook_salt ) ;
}
if ( hashconfig - > is_salted = = true )
{
hcfree ( hash_buf . salt ) ;
}
hcfree ( hash_buf . digest ) ;
return 0 ;
}
2016-10-06 08:55:14 +00:00
void hashes_destroy ( hashcat_ctx_t * hashcat_ctx )
2016-09-16 15:01:18 +00:00
{
2017-01-24 09:28:35 +00:00
hashconfig_t * hashconfig = hashcat_ctx - > hashconfig ;
2017-06-13 17:07:08 +00:00
hashes_t * hashes = hashcat_ctx - > hashes ;
2017-01-24 09:28:35 +00:00
user_options_t * user_options = hashcat_ctx - > user_options ;
2016-10-06 08:55:14 +00:00
2016-10-10 09:03:11 +00:00
hcfree ( hashes - > digests_buf ) ;
hcfree ( hashes - > digests_shown ) ;
2016-09-16 15:01:18 +00:00
2016-10-10 09:03:11 +00:00
hcfree ( hashes - > salts_buf ) ;
hcfree ( hashes - > salts_shown ) ;
2016-09-16 15:01:18 +00:00
2017-01-24 14:23:48 +00:00
if ( ( user_options - > username = = true ) | | ( hashconfig - > opts_type & OPTS_TYPE_HASH_COPY ) )
2017-01-24 09:28:35 +00:00
{
for ( u32 hash_pos = 0 ; hash_pos < hashes - > hashes_cnt ; hash_pos + + )
{
if ( user_options - > username = = true )
{
hcfree ( hashes - > hash_info [ hash_pos ] - > user ) ;
}
if ( hashconfig - > opts_type & OPTS_TYPE_HASH_COPY )
{
hcfree ( hashes - > hash_info [ hash_pos ] - > orighash ) ;
}
2017-02-13 15:46:37 +00:00
if ( hashconfig - > opts_type & OPTS_TYPE_HASH_SPLIT )
{
hcfree ( hashes - > hash_info [ hash_pos ] - > split ) ;
}
2017-01-24 09:28:35 +00:00
}
}
2016-10-10 09:03:11 +00:00
hcfree ( hashes - > hash_info ) ;
2016-09-16 15:01:18 +00:00
2017-01-24 14:23:48 +00:00
hcfree ( hashes - > esalts_buf ) ;
hcfree ( hashes - > hook_salts_buf ) ;
2016-10-30 21:22:26 +00:00
hcfree ( hashes - > out_buf ) ;
hcfree ( hashes - > tmp_buf ) ;
2017-06-13 17:07:08 +00:00
hcfree ( hashes - > st_digests_buf ) ;
hcfree ( hashes - > st_salts_buf ) ;
hcfree ( hashes - > st_esalts_buf ) ;
2017-06-14 10:07:33 +00:00
hcfree ( hashes - > st_hook_salts_buf ) ;
2017-06-13 17:07:08 +00:00
2016-10-01 22:00:21 +00:00
memset ( hashes , 0 , sizeof ( hashes_t ) ) ;
2016-09-16 15:01:18 +00:00
}
2016-09-23 19:41:05 +00:00
2016-10-06 08:55:14 +00:00
void hashes_logger ( hashcat_ctx_t * hashcat_ctx )
2016-09-23 19:41:05 +00:00
{
2016-10-06 08:55:14 +00:00
hashes_t * hashes = hashcat_ctx - > hashes ;
logfile_ctx_t * logfile_ctx = hashcat_ctx - > logfile_ctx ;
2016-09-23 19:41:05 +00:00
logfile_top_string ( hashes - > hashfile ) ;
logfile_top_uint ( hashes - > hashlist_mode ) ;
logfile_top_uint ( hashes - > hashlist_format ) ;
logfile_top_uint ( hashes - > hashes_cnt ) ;
logfile_top_uint ( hashes - > digests_cnt ) ;
2022-08-20 07:39:59 +00:00
logfile_top_uint ( hashes - > digests_done_pot ) ;
logfile_top_uint ( hashes - > digests_done_zero ) ;
2016-09-23 19:41:05 +00:00
logfile_top_uint ( hashes - > digests_done ) ;
logfile_top_uint ( hashes - > salts_cnt ) ;
logfile_top_uint ( hashes - > salts_done ) ;
}