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_INSIDE_KERNEL;
14 static const u32   DGST_POS0      = 14;
15 static const u32   DGST_POS1      = 15;
16 static const u32   DGST_POS2      = 6;
17 static const u32   DGST_POS3      = 7;
18 static const u32   DGST_SIZE      = DGST_SIZE_8_8;
19 static const u32   HASH_CATEGORY  = HASH_CATEGORY_DATABASE_SERVER;
20 static const char *HASH_NAME      = "MSSQL (2012, 2014)";
21 static const u64   KERN_TYPE      = 1730;
22 static const u32   OPTI_TYPE      = OPTI_TYPE_ZERO_BYTE
23                                   | OPTI_TYPE_PRECOMPUTE_INIT
24                                   | OPTI_TYPE_EARLY_SKIP
25                                   | OPTI_TYPE_NOT_ITERATED
26                                   | OPTI_TYPE_APPENDED_SALT
27                                   | OPTI_TYPE_USES_BITS_64
28                                   | OPTI_TYPE_RAW_HASH;
29 static const u64   OPTS_TYPE      = OPTS_TYPE_PT_GENERATE_BE
30                                   | OPTS_TYPE_PT_UTF16LE
31                                   | OPTS_TYPE_ST_ADD80
32                                   | OPTS_TYPE_ST_ADDBITS15
33                                   | OPTS_TYPE_ST_HEX;
34 static const u32   SALT_TYPE      = SALT_TYPE_EMBEDDED;
35 static const char *ST_PASS        = "hashcat";
36 static const char *ST_HASH        = "0x02003788006711b2e74e7d8cb4be96b1d187c962c5591a02d5a6ae81b3a4a094b26b7877958b26733e45016d929a756ed30d0a5ee65d3ce1970f9b7bf946e705c595f07625b1";
37 
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)38 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)39 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)40 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)41 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)42 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)43 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)44 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)45 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)46 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)47 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)48 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)49 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)50 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)51 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;         }
52 
53 static const char *SIGNATURE_MSSQL2012 = "0x0200";
54 
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)55 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)
56 {
57   u64 *digest = (u64 *) digest_buf;
58 
59   token_t token;
60 
61   token.token_cnt  = 3;
62 
63   token.signatures_cnt    = 1;
64   token.signatures_buf[0] = SIGNATURE_MSSQL2012;
65 
66   token.len[0]     = 6;
67   token.attr[0]    = TOKEN_ATTR_FIXED_LENGTH
68                    | TOKEN_ATTR_VERIFY_SIGNATURE;
69 
70   token.len[1]     = 8;
71   token.attr[1]    = TOKEN_ATTR_FIXED_LENGTH
72                    | TOKEN_ATTR_VERIFY_HEX;
73 
74   token.len[2]     = 128;
75   token.attr[2]    = TOKEN_ATTR_FIXED_LENGTH
76                    | TOKEN_ATTR_VERIFY_HEX;
77 
78   const int rc_tokenizer = input_tokenizer ((const u8 *) line_buf, line_len, &token);
79 
80   if (rc_tokenizer != PARSER_OK) return (rc_tokenizer);
81 
82   const u8 *hash_pos = token.buf[2];
83 
84   digest[0] = hex_to_u64 (hash_pos +   0);
85   digest[1] = hex_to_u64 (hash_pos +  16);
86   digest[2] = hex_to_u64 (hash_pos +  32);
87   digest[3] = hex_to_u64 (hash_pos +  48);
88   digest[4] = hex_to_u64 (hash_pos +  64);
89   digest[5] = hex_to_u64 (hash_pos +  80);
90   digest[6] = hex_to_u64 (hash_pos +  96);
91   digest[7] = hex_to_u64 (hash_pos + 112);
92 
93   digest[0] = byte_swap_64 (digest[0]);
94   digest[1] = byte_swap_64 (digest[1]);
95   digest[2] = byte_swap_64 (digest[2]);
96   digest[3] = byte_swap_64 (digest[3]);
97   digest[4] = byte_swap_64 (digest[4]);
98   digest[5] = byte_swap_64 (digest[5]);
99   digest[6] = byte_swap_64 (digest[6]);
100   digest[7] = byte_swap_64 (digest[7]);
101 
102   if (hashconfig->opti_type & OPTI_TYPE_OPTIMIZED_KERNEL)
103   {
104     digest[0] -= SHA512M_A;
105     digest[1] -= SHA512M_B;
106     digest[2] -= SHA512M_C;
107     digest[3] -= SHA512M_D;
108     digest[4] -= SHA512M_E;
109     digest[5] -= SHA512M_F;
110     digest[6] -= SHA512M_G;
111     digest[7] -= SHA512M_H;
112   }
113 
114   const u8 *salt_pos = token.buf[1];
115   const int salt_len = token.len[1];
116 
117   const bool parse_rc = generic_salt_decode (hashconfig, salt_pos, salt_len, (u8 *) salt->salt_buf, (int *) &salt->salt_len);
118 
119   if (parse_rc == false) return (PARSER_SALT_LENGTH);
120 
121   return (PARSER_OK);
122 }
123 
module_hash_encode(MAYBE_UNUSED const hashconfig_t * hashconfig,MAYBE_UNUSED const void * digest_buf,MAYBE_UNUSED const salt_t * salt,MAYBE_UNUSED const void * esalt_buf,MAYBE_UNUSED const void * hook_salt_buf,MAYBE_UNUSED const hashinfo_t * hash_info,char * line_buf,MAYBE_UNUSED const int line_size)124 int module_hash_encode (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const void *digest_buf, MAYBE_UNUSED const salt_t *salt, MAYBE_UNUSED const void *esalt_buf, MAYBE_UNUSED const void *hook_salt_buf, MAYBE_UNUSED const hashinfo_t *hash_info, char *line_buf, MAYBE_UNUSED const int line_size)
125 {
126   const u64 *digest = (const u64 *) digest_buf;
127 
128   u64 tmp[8];
129 
130   tmp[0] = digest[0];
131   tmp[1] = digest[1];
132   tmp[2] = digest[2];
133   tmp[3] = digest[3];
134   tmp[4] = digest[4];
135   tmp[5] = digest[5];
136   tmp[6] = digest[6];
137   tmp[7] = digest[7];
138 
139   if (hashconfig->opti_type & OPTI_TYPE_OPTIMIZED_KERNEL)
140   {
141     tmp[0] += SHA512M_A;
142     tmp[1] += SHA512M_B;
143     tmp[2] += SHA512M_C;
144     tmp[3] += SHA512M_D;
145     tmp[4] += SHA512M_E;
146     tmp[5] += SHA512M_F;
147     tmp[6] += SHA512M_G;
148     tmp[7] += SHA512M_H;
149   }
150 
151   char tmp_salt[SALT_MAX * 2];
152 
153   const int salt_len = generic_salt_encode (hashconfig, (const u8 *) salt->salt_buf, (const int) salt->salt_len, (u8 *) tmp_salt);
154 
155   tmp_salt[salt_len] = 0;
156 
157   const int line_len = snprintf (line_buf, line_size, "0x0200%s%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x",
158     tmp_salt,
159     v32b_from_v64 (tmp[0]), v32a_from_v64 (tmp[0]),
160     v32b_from_v64 (tmp[1]), v32a_from_v64 (tmp[1]),
161     v32b_from_v64 (tmp[2]), v32a_from_v64 (tmp[2]),
162     v32b_from_v64 (tmp[3]), v32a_from_v64 (tmp[3]),
163     v32b_from_v64 (tmp[4]), v32a_from_v64 (tmp[4]),
164     v32b_from_v64 (tmp[5]), v32a_from_v64 (tmp[5]),
165     v32b_from_v64 (tmp[6]), v32a_from_v64 (tmp[6]),
166     v32b_from_v64 (tmp[7]), v32a_from_v64 (tmp[7]));
167 
168   return line_len;
169 }
170 
module_init(module_ctx_t * module_ctx)171 void module_init (module_ctx_t *module_ctx)
172 {
173   module_ctx->module_context_size             = MODULE_CONTEXT_SIZE_CURRENT;
174   module_ctx->module_interface_version        = MODULE_INTERFACE_VERSION_CURRENT;
175 
176   module_ctx->module_attack_exec              = module_attack_exec;
177   module_ctx->module_benchmark_esalt          = MODULE_DEFAULT;
178   module_ctx->module_benchmark_hook_salt      = MODULE_DEFAULT;
179   module_ctx->module_benchmark_mask           = MODULE_DEFAULT;
180   module_ctx->module_benchmark_salt           = MODULE_DEFAULT;
181   module_ctx->module_build_plain_postprocess  = MODULE_DEFAULT;
182   module_ctx->module_deep_comp_kernel         = MODULE_DEFAULT;
183   module_ctx->module_deprecated_notice        = MODULE_DEFAULT;
184   module_ctx->module_dgst_pos0                = module_dgst_pos0;
185   module_ctx->module_dgst_pos1                = module_dgst_pos1;
186   module_ctx->module_dgst_pos2                = module_dgst_pos2;
187   module_ctx->module_dgst_pos3                = module_dgst_pos3;
188   module_ctx->module_dgst_size                = module_dgst_size;
189   module_ctx->module_dictstat_disable         = MODULE_DEFAULT;
190   module_ctx->module_esalt_size               = MODULE_DEFAULT;
191   module_ctx->module_extra_buffer_size        = MODULE_DEFAULT;
192   module_ctx->module_extra_tmp_size           = MODULE_DEFAULT;
193   module_ctx->module_extra_tuningdb_block     = MODULE_DEFAULT;
194   module_ctx->module_forced_outfile_format    = MODULE_DEFAULT;
195   module_ctx->module_hash_binary_count        = MODULE_DEFAULT;
196   module_ctx->module_hash_binary_parse        = MODULE_DEFAULT;
197   module_ctx->module_hash_binary_save         = MODULE_DEFAULT;
198   module_ctx->module_hash_decode_potfile      = MODULE_DEFAULT;
199   module_ctx->module_hash_decode_zero_hash    = MODULE_DEFAULT;
200   module_ctx->module_hash_decode              = module_hash_decode;
201   module_ctx->module_hash_encode_status       = MODULE_DEFAULT;
202   module_ctx->module_hash_encode_potfile      = MODULE_DEFAULT;
203   module_ctx->module_hash_encode              = module_hash_encode;
204   module_ctx->module_hash_init_selftest       = MODULE_DEFAULT;
205   module_ctx->module_hash_mode                = MODULE_DEFAULT;
206   module_ctx->module_hash_category            = module_hash_category;
207   module_ctx->module_hash_name                = module_hash_name;
208   module_ctx->module_hashes_count_min         = MODULE_DEFAULT;
209   module_ctx->module_hashes_count_max         = MODULE_DEFAULT;
210   module_ctx->module_hlfmt_disable            = MODULE_DEFAULT;
211   module_ctx->module_hook_extra_param_size    = MODULE_DEFAULT;
212   module_ctx->module_hook_extra_param_init    = MODULE_DEFAULT;
213   module_ctx->module_hook_extra_param_term    = MODULE_DEFAULT;
214   module_ctx->module_hook12                   = MODULE_DEFAULT;
215   module_ctx->module_hook23                   = MODULE_DEFAULT;
216   module_ctx->module_hook_salt_size           = MODULE_DEFAULT;
217   module_ctx->module_hook_size                = MODULE_DEFAULT;
218   module_ctx->module_jit_build_options        = MODULE_DEFAULT;
219   module_ctx->module_jit_cache_disable        = MODULE_DEFAULT;
220   module_ctx->module_kernel_accel_max         = MODULE_DEFAULT;
221   module_ctx->module_kernel_accel_min         = MODULE_DEFAULT;
222   module_ctx->module_kernel_loops_max         = MODULE_DEFAULT;
223   module_ctx->module_kernel_loops_min         = MODULE_DEFAULT;
224   module_ctx->module_kernel_threads_max       = MODULE_DEFAULT;
225   module_ctx->module_kernel_threads_min       = MODULE_DEFAULT;
226   module_ctx->module_kern_type                = module_kern_type;
227   module_ctx->module_kern_type_dynamic        = MODULE_DEFAULT;
228   module_ctx->module_opti_type                = module_opti_type;
229   module_ctx->module_opts_type                = module_opts_type;
230   module_ctx->module_outfile_check_disable    = MODULE_DEFAULT;
231   module_ctx->module_outfile_check_nocomp     = MODULE_DEFAULT;
232   module_ctx->module_potfile_custom_check     = MODULE_DEFAULT;
233   module_ctx->module_potfile_disable          = MODULE_DEFAULT;
234   module_ctx->module_potfile_keep_all_hashes  = MODULE_DEFAULT;
235   module_ctx->module_pwdump_column            = MODULE_DEFAULT;
236   module_ctx->module_pw_max                   = MODULE_DEFAULT;
237   module_ctx->module_pw_min                   = MODULE_DEFAULT;
238   module_ctx->module_salt_max                 = MODULE_DEFAULT;
239   module_ctx->module_salt_min                 = MODULE_DEFAULT;
240   module_ctx->module_salt_type                = module_salt_type;
241   module_ctx->module_separator                = MODULE_DEFAULT;
242   module_ctx->module_st_hash                  = module_st_hash;
243   module_ctx->module_st_pass                  = module_st_pass;
244   module_ctx->module_tmp_size                 = MODULE_DEFAULT;
245   module_ctx->module_unstable_warning         = MODULE_DEFAULT;
246   module_ctx->module_warmup_disable           = MODULE_DEFAULT;
247 }
248