1 /**
2  * Author......: See docs/credits.txt
3  * License.....: MIT
4  */
5 
6 #include "common.h"
7 #include "types.h"
8 #include "modules.h"
9 #include "bitops.h"
10 #include "convert.h"
11 #include "shared.h"
12 
13 static const u32   ATTACK_EXEC    = ATTACK_EXEC_OUTSIDE_KERNEL;
14 static const u32   DGST_POS0      = 0;
15 static const u32   DGST_POS1      = 1;
16 static const u32   DGST_POS2      = 2;
17 static const u32   DGST_POS3      = 3;
18 static const u32   DGST_SIZE      = DGST_SIZE_4_8;
19 static const u32   HASH_CATEGORY  = HASH_CATEGORY_PASSWORD_MANAGER;
20 static const char *HASH_NAME      = "Password Safe v3";
21 static const u64   KERN_TYPE      = 5200;
22 static const u32   OPTI_TYPE      = OPTI_TYPE_ZERO_BYTE
23                                   | OPTI_TYPE_SLOW_HASH_SIMD_LOOP;
24 static const u64   OPTS_TYPE      = OPTS_TYPE_PT_GENERATE_LE
25                                   | OPTS_TYPE_BINARY_HASHFILE;
26 static const u32   SALT_TYPE      = SALT_TYPE_EMBEDDED;
27 static const char *ST_PASS        = "hashcat";
28 static const char *ST_HASH        = "50575333e4e2a590a5e5c8269f57ec04a8a1c0c03da55b311c51236dab8c6b96b0afca02000800005eaeee20c6cc10d5caa6522b3ca545c41d9133d630ca08f467b7aae8a2bbef51aa2df968d10b9c4cfb17a182c0add7acb8c153794f51337e12f472f451d10e6dcac664ed760606aabdbb6b794a80d6ce2a330100c76de0ff961a45cca21576b893d826c52f272b97cdf48aca6fbe6c74b039f81c61b7d632fb6fddd9f96162ab1effd69a4598a331e855e38792e5365272d4791bf991d248e1585a9ad20ea3d77b5d2ef9a711ef90a70ec6991cb578f1b8bdaa9efa7b0039e9ea96f777491713047bdd99fa1d78f06f23406a66046b387d3034e46b1f84129bba853cc18fa49f107dc0290547258d30566a4b1b363ff4c1c16cb2f5f400059833d4b651bfa508200cbdc7a75fc57ef90eb1d90b0deea8505753332d454f46505753332d454f466236710e2e2477878e738b60d0aa2834a96b01e97764fe980243a06ad16939d1";
29 
module_attack_exec(MAYBE_UNUSED const hashconfig_t * hashconfig,MAYBE_UNUSED const user_options_t * user_options,MAYBE_UNUSED const user_options_extra_t * user_options_extra)30 u32         module_attack_exec    (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return ATTACK_EXEC;     }
module_dgst_pos0(MAYBE_UNUSED const hashconfig_t * hashconfig,MAYBE_UNUSED const user_options_t * user_options,MAYBE_UNUSED const user_options_extra_t * user_options_extra)31 u32         module_dgst_pos0      (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return DGST_POS0;       }
module_dgst_pos1(MAYBE_UNUSED const hashconfig_t * hashconfig,MAYBE_UNUSED const user_options_t * user_options,MAYBE_UNUSED const user_options_extra_t * user_options_extra)32 u32         module_dgst_pos1      (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return DGST_POS1;       }
module_dgst_pos2(MAYBE_UNUSED const hashconfig_t * hashconfig,MAYBE_UNUSED const user_options_t * user_options,MAYBE_UNUSED const user_options_extra_t * user_options_extra)33 u32         module_dgst_pos2      (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return DGST_POS2;       }
module_dgst_pos3(MAYBE_UNUSED const hashconfig_t * hashconfig,MAYBE_UNUSED const user_options_t * user_options,MAYBE_UNUSED const user_options_extra_t * user_options_extra)34 u32         module_dgst_pos3      (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return DGST_POS3;       }
module_dgst_size(MAYBE_UNUSED const hashconfig_t * hashconfig,MAYBE_UNUSED const user_options_t * user_options,MAYBE_UNUSED const user_options_extra_t * user_options_extra)35 u32         module_dgst_size      (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return DGST_SIZE;       }
module_hash_category(MAYBE_UNUSED const hashconfig_t * hashconfig,MAYBE_UNUSED const user_options_t * user_options,MAYBE_UNUSED const user_options_extra_t * user_options_extra)36 u32         module_hash_category  (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return HASH_CATEGORY;   }
module_hash_name(MAYBE_UNUSED const hashconfig_t * hashconfig,MAYBE_UNUSED const user_options_t * user_options,MAYBE_UNUSED const user_options_extra_t * user_options_extra)37 const char *module_hash_name      (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return HASH_NAME;       }
module_kern_type(MAYBE_UNUSED const hashconfig_t * hashconfig,MAYBE_UNUSED const user_options_t * user_options,MAYBE_UNUSED const user_options_extra_t * user_options_extra)38 u64         module_kern_type      (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return KERN_TYPE;       }
module_opti_type(MAYBE_UNUSED const hashconfig_t * hashconfig,MAYBE_UNUSED const user_options_t * user_options,MAYBE_UNUSED const user_options_extra_t * user_options_extra)39 u32         module_opti_type      (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return OPTI_TYPE;       }
module_opts_type(MAYBE_UNUSED const hashconfig_t * hashconfig,MAYBE_UNUSED const user_options_t * user_options,MAYBE_UNUSED const user_options_extra_t * user_options_extra)40 u64         module_opts_type      (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return OPTS_TYPE;       }
module_salt_type(MAYBE_UNUSED const hashconfig_t * hashconfig,MAYBE_UNUSED const user_options_t * user_options,MAYBE_UNUSED const user_options_extra_t * user_options_extra)41 u32         module_salt_type      (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return SALT_TYPE;       }
module_st_hash(MAYBE_UNUSED const hashconfig_t * hashconfig,MAYBE_UNUSED const user_options_t * user_options,MAYBE_UNUSED const user_options_extra_t * user_options_extra)42 const char *module_st_hash        (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return ST_HASH;         }
module_st_pass(MAYBE_UNUSED const hashconfig_t * hashconfig,MAYBE_UNUSED const user_options_t * user_options,MAYBE_UNUSED const user_options_extra_t * user_options_extra)43 const char *module_st_pass        (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return ST_PASS;         }
44 
45 typedef struct psafe3
46 {
47   char signature[4];
48   u32  salt_buf[8];
49   u32  iterations;
50   u32  hash_buf[8];
51 
52 } psafe3_t;
53 
54 typedef struct pwsafe3_tmp
55 {
56   u32 digest_buf[8];
57 
58 } pwsafe3_tmp_t;
59 
60 static const char *SIGNATURE_PSAFE3 = "PWS3";
61 
module_jit_build_options(MAYBE_UNUSED const hashconfig_t * hashconfig,MAYBE_UNUSED const user_options_t * user_options,MAYBE_UNUSED const user_options_extra_t * user_options_extra,MAYBE_UNUSED const hashes_t * hashes,MAYBE_UNUSED const hc_device_param_t * device_param)62 char *module_jit_build_options (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra, MAYBE_UNUSED const hashes_t *hashes, MAYBE_UNUSED const hc_device_param_t *device_param)
63 {
64   char *jit_build_options = NULL;
65 
66   // Extra treatment for Apple systems
67   if (device_param->opencl_platform_vendor_id == VENDOR_ID_APPLE)
68   {
69     return jit_build_options;
70   }
71 
72   // Intel CPU
73   if ((device_param->opencl_device_vendor_id == VENDOR_ID_INTEL_SDK) && (device_param->opencl_device_type & CL_DEVICE_TYPE_CPU))
74   {
75     hc_asprintf (&jit_build_options, "-D _unroll");
76   }
77 
78   // NVIDIA GPU
79   if (device_param->opencl_device_vendor_id == VENDOR_ID_NV)
80   {
81     hc_asprintf (&jit_build_options, "-D _unroll");
82   }
83 
84   // HIP
85   if (device_param->opencl_device_vendor_id == VENDOR_ID_AMD_USE_HIP)
86   {
87     hc_asprintf (&jit_build_options, "-D _unroll");
88   }
89 
90   // ROCM
91   if ((device_param->opencl_device_vendor_id == VENDOR_ID_AMD) && (device_param->has_vperm == true))
92   {
93     hc_asprintf (&jit_build_options, "-D _unroll");
94   }
95 
96   return jit_build_options;
97 }
98 
module_pw_max(MAYBE_UNUSED const hashconfig_t * hashconfig,MAYBE_UNUSED const user_options_t * user_options,MAYBE_UNUSED const user_options_extra_t * user_options_extra)99 u32 module_pw_max (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra)
100 {
101   const u32 pw_max = PW_MAX;
102 
103   return pw_max;
104 }
105 
module_tmp_size(MAYBE_UNUSED const hashconfig_t * hashconfig,MAYBE_UNUSED const user_options_t * user_options,MAYBE_UNUSED const user_options_extra_t * user_options_extra)106 u64 module_tmp_size (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra)
107 {
108   const u64 tmp_size = (const u64) sizeof (pwsafe3_tmp_t);
109 
110   return tmp_size;
111 }
112 
module_outfile_check_disable(MAYBE_UNUSED const hashconfig_t * hashconfig,MAYBE_UNUSED const user_options_t * user_options,MAYBE_UNUSED const user_options_extra_t * user_options_extra)113 bool module_outfile_check_disable (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra)
114 {
115   const bool outfile_check_disable = true;
116 
117   return outfile_check_disable;
118 }
119 
module_potfile_disable(MAYBE_UNUSED const hashconfig_t * hashconfig,MAYBE_UNUSED const user_options_t * user_options,MAYBE_UNUSED const user_options_extra_t * user_options_extra)120 bool module_potfile_disable (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra)
121 {
122   const bool potfile_disable = true;
123 
124   return potfile_disable;
125 }
126 
module_hash_decode(MAYBE_UNUSED const hashconfig_t * hashconfig,MAYBE_UNUSED void * digest_buf,MAYBE_UNUSED salt_t * salt,MAYBE_UNUSED void * esalt_buf,MAYBE_UNUSED void * hook_salt_buf,MAYBE_UNUSED hashinfo_t * hash_info,const char * line_buf,MAYBE_UNUSED const int line_len)127 int module_hash_decode (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED void *digest_buf, MAYBE_UNUSED salt_t *salt, MAYBE_UNUSED void *esalt_buf, MAYBE_UNUSED void *hook_salt_buf, MAYBE_UNUSED hashinfo_t *hash_info, const char *line_buf, MAYBE_UNUSED const int line_len)
128 {
129   u32 *digest = (u32 *) digest_buf;
130 
131   if (line_len == 0) return (PARSER_HASH_LENGTH);
132 
133   HCFILE fp;
134 
135   if (hc_fopen (&fp, (const char *) line_buf, "rb") == false) return (PARSER_HASH_FILE);
136 
137   psafe3_t in;
138 
139   memset (&in, 0, sizeof (psafe3_t));
140 
141   const size_t n = hc_fread (&in, sizeof (psafe3_t), 1, &fp);
142 
143   hc_fclose (&fp);
144 
145   if (n != 1) return (PARSER_PSAFE3_FILE_SIZE);
146 
147   if (memcmp (SIGNATURE_PSAFE3, in.signature, 4) != 0) return (PARSER_SIGNATURE_UNMATCHED);
148 
149   salt->salt_iter = in.iterations + 1;
150 
151   salt->salt_buf[0] = in.salt_buf[0];
152   salt->salt_buf[1] = in.salt_buf[1];
153   salt->salt_buf[2] = in.salt_buf[2];
154   salt->salt_buf[3] = in.salt_buf[3];
155   salt->salt_buf[4] = in.salt_buf[4];
156   salt->salt_buf[5] = in.salt_buf[5];
157   salt->salt_buf[6] = in.salt_buf[6];
158   salt->salt_buf[7] = in.salt_buf[7];
159 
160   salt->salt_len = 32;
161 
162   digest[0] = in.hash_buf[0];
163   digest[1] = in.hash_buf[1];
164   digest[2] = in.hash_buf[2];
165   digest[3] = in.hash_buf[3];
166   digest[4] = in.hash_buf[4];
167   digest[5] = in.hash_buf[5];
168   digest[6] = in.hash_buf[6];
169   digest[7] = in.hash_buf[7];
170 
171   digest[0] = byte_swap_32 (digest[0]);
172   digest[1] = byte_swap_32 (digest[1]);
173   digest[2] = byte_swap_32 (digest[2]);
174   digest[3] = byte_swap_32 (digest[3]);
175   digest[4] = byte_swap_32 (digest[4]);
176   digest[5] = byte_swap_32 (digest[5]);
177   digest[6] = byte_swap_32 (digest[6]);
178   digest[7] = byte_swap_32 (digest[7]);
179 
180   return (PARSER_OK);
181 }
182 
module_init(module_ctx_t * module_ctx)183 void module_init (module_ctx_t *module_ctx)
184 {
185   module_ctx->module_context_size             = MODULE_CONTEXT_SIZE_CURRENT;
186   module_ctx->module_interface_version        = MODULE_INTERFACE_VERSION_CURRENT;
187 
188   module_ctx->module_attack_exec              = module_attack_exec;
189   module_ctx->module_benchmark_esalt          = MODULE_DEFAULT;
190   module_ctx->module_benchmark_hook_salt      = MODULE_DEFAULT;
191   module_ctx->module_benchmark_mask           = MODULE_DEFAULT;
192   module_ctx->module_benchmark_salt           = MODULE_DEFAULT;
193   module_ctx->module_build_plain_postprocess  = MODULE_DEFAULT;
194   module_ctx->module_deep_comp_kernel         = MODULE_DEFAULT;
195   module_ctx->module_deprecated_notice        = MODULE_DEFAULT;
196   module_ctx->module_dgst_pos0                = module_dgst_pos0;
197   module_ctx->module_dgst_pos1                = module_dgst_pos1;
198   module_ctx->module_dgst_pos2                = module_dgst_pos2;
199   module_ctx->module_dgst_pos3                = module_dgst_pos3;
200   module_ctx->module_dgst_size                = module_dgst_size;
201   module_ctx->module_dictstat_disable         = MODULE_DEFAULT;
202   module_ctx->module_esalt_size               = MODULE_DEFAULT;
203   module_ctx->module_extra_buffer_size        = MODULE_DEFAULT;
204   module_ctx->module_extra_tmp_size           = MODULE_DEFAULT;
205   module_ctx->module_extra_tuningdb_block     = MODULE_DEFAULT;
206   module_ctx->module_forced_outfile_format    = MODULE_DEFAULT;
207   module_ctx->module_hash_binary_count        = MODULE_DEFAULT;
208   module_ctx->module_hash_binary_parse        = MODULE_DEFAULT;
209   module_ctx->module_hash_binary_save         = MODULE_DEFAULT;
210   module_ctx->module_hash_decode_potfile      = MODULE_DEFAULT;
211   module_ctx->module_hash_decode_zero_hash    = MODULE_DEFAULT;
212   module_ctx->module_hash_decode              = module_hash_decode;
213   module_ctx->module_hash_encode_status       = MODULE_DEFAULT;
214   module_ctx->module_hash_encode_potfile      = MODULE_DEFAULT;
215   module_ctx->module_hash_encode              = MODULE_DEFAULT;
216   module_ctx->module_hash_init_selftest       = MODULE_DEFAULT;
217   module_ctx->module_hash_mode                = MODULE_DEFAULT;
218   module_ctx->module_hash_category            = module_hash_category;
219   module_ctx->module_hash_name                = module_hash_name;
220   module_ctx->module_hashes_count_min         = MODULE_DEFAULT;
221   module_ctx->module_hashes_count_max         = MODULE_DEFAULT;
222   module_ctx->module_hlfmt_disable            = MODULE_DEFAULT;
223   module_ctx->module_hook_extra_param_size    = MODULE_DEFAULT;
224   module_ctx->module_hook_extra_param_init    = MODULE_DEFAULT;
225   module_ctx->module_hook_extra_param_term    = MODULE_DEFAULT;
226   module_ctx->module_hook12                   = MODULE_DEFAULT;
227   module_ctx->module_hook23                   = MODULE_DEFAULT;
228   module_ctx->module_hook_salt_size           = MODULE_DEFAULT;
229   module_ctx->module_hook_size                = MODULE_DEFAULT;
230   module_ctx->module_jit_build_options        = module_jit_build_options;
231   module_ctx->module_jit_cache_disable        = MODULE_DEFAULT;
232   module_ctx->module_kernel_accel_max         = MODULE_DEFAULT;
233   module_ctx->module_kernel_accel_min         = MODULE_DEFAULT;
234   module_ctx->module_kernel_loops_max         = MODULE_DEFAULT;
235   module_ctx->module_kernel_loops_min         = MODULE_DEFAULT;
236   module_ctx->module_kernel_threads_max       = MODULE_DEFAULT;
237   module_ctx->module_kernel_threads_min       = MODULE_DEFAULT;
238   module_ctx->module_kern_type                = module_kern_type;
239   module_ctx->module_kern_type_dynamic        = MODULE_DEFAULT;
240   module_ctx->module_opti_type                = module_opti_type;
241   module_ctx->module_opts_type                = module_opts_type;
242   module_ctx->module_outfile_check_disable    = module_outfile_check_disable;
243   module_ctx->module_outfile_check_nocomp     = MODULE_DEFAULT;
244   module_ctx->module_potfile_custom_check     = MODULE_DEFAULT;
245   module_ctx->module_potfile_disable          = module_potfile_disable;
246   module_ctx->module_potfile_keep_all_hashes  = MODULE_DEFAULT;
247   module_ctx->module_pwdump_column            = MODULE_DEFAULT;
248   module_ctx->module_pw_max                   = module_pw_max;
249   module_ctx->module_pw_min                   = MODULE_DEFAULT;
250   module_ctx->module_salt_max                 = MODULE_DEFAULT;
251   module_ctx->module_salt_min                 = MODULE_DEFAULT;
252   module_ctx->module_salt_type                = module_salt_type;
253   module_ctx->module_separator                = MODULE_DEFAULT;
254   module_ctx->module_st_hash                  = module_st_hash;
255   module_ctx->module_st_pass                  = module_st_pass;
256   module_ctx->module_tmp_size                 = module_tmp_size;
257   module_ctx->module_unstable_warning         = MODULE_DEFAULT;
258   module_ctx->module_warmup_disable           = MODULE_DEFAULT;
259 }
260