1 /**
2 * Author......: See docs/credits.txt
3 * License.....: MIT
4 *
5 * based on work by Nicolas B. <mrtchuss at gmail.com>
6 *
7 */
8
9 #include "common.h"
10 #include "types.h"
11 #include "modules.h"
12 #include "bitops.h"
13 #include "convert.h"
14 #include "shared.h"
15
16 static const u32 ATTACK_EXEC = ATTACK_EXEC_INSIDE_KERNEL;
17 static const u32 DGST_POS0 = 3;
18 static const u32 DGST_POS1 = 7;
19 static const u32 DGST_POS2 = 2;
20 static const u32 DGST_POS3 = 6;
21 static const u32 DGST_SIZE = DGST_SIZE_4_8;
22 static const u32 HASH_CATEGORY = HASH_CATEGORY_OS;
23 static const char *HASH_NAME = "FortiGate256 (FortiOS256)";
24 static const u64 KERN_TYPE = 26300;
25 static const u32 OPTI_TYPE = OPTI_TYPE_PRECOMPUTE_INIT
26 | OPTI_TYPE_EARLY_SKIP
27 | OPTI_TYPE_NOT_ITERATED;
28 static const u64 OPTS_TYPE = OPTS_TYPE_PT_GENERATE_BE;
29 static const u32 SALT_TYPE = SALT_TYPE_EMBEDDED;
30 static const char *ST_PASS = "hashcat";
31 static const char *ST_HASH = "SH2lpcpFXM5QRlWYwY5vL9+5svfYyb+c79qENpxEoB3NtZpVxKwHjuq/9TH88U=";
32
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)33 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)34 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)35 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)36 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)37 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)38 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)39 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)40 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)41 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)42 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)43 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)44 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)45 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)46 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; }
47
48 static const char *SIGNATURE_FORTIGATE = "SH2";
49
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)50 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)
51 {
52 u32 *digest = (u32 *) digest_buf;
53
54 token_t token;
55
56 token.token_cnt = 2;
57
58 token.signatures_cnt = 1;
59 token.signatures_buf[0] = SIGNATURE_FORTIGATE;
60
61 token.len[0] = 3;
62 token.attr[0] = TOKEN_ATTR_FIXED_LENGTH
63 | TOKEN_ATTR_VERIFY_SIGNATURE;
64
65 token.len[1] = 60;
66 token.attr[1] = TOKEN_ATTR_FIXED_LENGTH
67 | TOKEN_ATTR_VERIFY_BASE64A;
68
69 const int rc_tokenizer = input_tokenizer ((const u8 *) line_buf, line_len, &token);
70
71 if (rc_tokenizer != PARSER_OK) return (rc_tokenizer);
72
73 /**
74 * verify data
75 */
76
77 const u8 *hash_pos = token.buf[1];
78 const int hash_len = token.len[1];
79
80 // decode salt + SHA1 hash (12 + 20 = 32)
81 //new 12+32=44
82
83 u8 tmp_buf[100] = { 0 };
84
85 const int decoded_len = base64_decode (base64_to_int, hash_pos, hash_len, tmp_buf);
86
87 if (decoded_len != 44) return (PARSER_HASH_LENGTH);
88
89 /**
90 * store data
91 */
92
93 // salt
94
95 u32 salt_len = 12;
96
97 memcpy (salt->salt_buf, tmp_buf, salt_len);
98
99 salt->salt_len = salt_len;
100
101 // digest
102
103 memcpy (digest, tmp_buf + salt_len, 32);
104
105 digest[0] = byte_swap_32 (digest[0]);
106 digest[1] = byte_swap_32 (digest[1]);
107 digest[2] = byte_swap_32 (digest[2]);
108 digest[3] = byte_swap_32 (digest[3]);
109 digest[4] = byte_swap_32 (digest[4]);
110 digest[5] = byte_swap_32 (digest[5]);
111 digest[6] = byte_swap_32 (digest[6]);
112 digest[7] = byte_swap_32 (digest[7]);
113
114 if (hashconfig->opti_type & OPTI_TYPE_OPTIMIZED_KERNEL)
115 {
116 digest[0] -= SHA256M_A;
117 digest[1] -= SHA256M_B;
118 digest[2] -= SHA256M_C;
119 digest[3] -= SHA256M_D;
120 digest[4] -= SHA256M_E;
121 digest[5] -= SHA256M_F;
122 digest[6] -= SHA256M_G;
123 digest[7] -= SHA256M_H;
124 }
125
126 return (PARSER_OK);
127 }
128
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)129 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)
130 {
131 const u32 *digest = (const u32 *) digest_buf;
132
133 char tmp_buf[64];
134
135 // salt
136
137 memcpy (tmp_buf, salt->salt_buf, 12);
138
139 // digest
140
141 u32 tmp[8];
142
143 tmp[0] = digest[0];
144 tmp[1] = digest[1];
145 tmp[2] = digest[2];
146 tmp[3] = digest[3];
147 tmp[4] = digest[4];
148 tmp[5] = digest[5];
149 tmp[6] = digest[6];
150 tmp[7] = digest[7];
151
152 if (hashconfig->opti_type & OPTI_TYPE_OPTIMIZED_KERNEL)
153 {
154 tmp[0] += SHA256M_A;
155 tmp[1] += SHA256M_B;
156 tmp[2] += SHA256M_C;
157 tmp[3] += SHA256M_D;
158 tmp[4] += SHA256M_E;
159 tmp[5] += SHA256M_F;
160 tmp[6] += SHA256M_G;
161 tmp[7] += SHA256M_H;
162 }
163
164 tmp[0] = byte_swap_32 (tmp[0]);
165 tmp[1] = byte_swap_32 (tmp[1]);
166 tmp[2] = byte_swap_32 (tmp[2]);
167 tmp[3] = byte_swap_32 (tmp[3]);
168 tmp[4] = byte_swap_32 (tmp[4]);
169 tmp[5] = byte_swap_32 (tmp[5]);
170 tmp[6] = byte_swap_32 (tmp[6]);
171 tmp[7] = byte_swap_32 (tmp[7]);
172
173 memcpy (tmp_buf + 12, tmp, 32);
174
175 // base64 encode (salt + SHA1)
176 // new would be salt+sha256
177
178 char ptr_plain[64];
179
180 base64_encode (int_to_base64, (const u8 *) tmp_buf, 12 + 32, (u8 *) ptr_plain);
181
182 ptr_plain[60] = 0;
183
184 const int line_len = snprintf (line_buf, line_size, "%s%s", SIGNATURE_FORTIGATE, ptr_plain);
185
186 return line_len;
187 }
188
module_init(module_ctx_t * module_ctx)189 void module_init (module_ctx_t *module_ctx)
190 {
191 module_ctx->module_context_size = MODULE_CONTEXT_SIZE_CURRENT;
192 module_ctx->module_interface_version = MODULE_INTERFACE_VERSION_CURRENT;
193
194 module_ctx->module_attack_exec = module_attack_exec;
195 module_ctx->module_benchmark_esalt = MODULE_DEFAULT;
196 module_ctx->module_benchmark_hook_salt = MODULE_DEFAULT;
197 module_ctx->module_benchmark_mask = MODULE_DEFAULT;
198 module_ctx->module_benchmark_salt = MODULE_DEFAULT;
199 module_ctx->module_build_plain_postprocess = MODULE_DEFAULT;
200 module_ctx->module_deep_comp_kernel = MODULE_DEFAULT;
201 module_ctx->module_deprecated_notice = MODULE_DEFAULT;
202 module_ctx->module_dgst_pos0 = module_dgst_pos0;
203 module_ctx->module_dgst_pos1 = module_dgst_pos1;
204 module_ctx->module_dgst_pos2 = module_dgst_pos2;
205 module_ctx->module_dgst_pos3 = module_dgst_pos3;
206 module_ctx->module_dgst_size = module_dgst_size;
207 module_ctx->module_dictstat_disable = MODULE_DEFAULT;
208 module_ctx->module_esalt_size = MODULE_DEFAULT;
209 module_ctx->module_extra_buffer_size = MODULE_DEFAULT;
210 module_ctx->module_extra_tmp_size = MODULE_DEFAULT;
211 module_ctx->module_extra_tuningdb_block = MODULE_DEFAULT;
212 module_ctx->module_forced_outfile_format = MODULE_DEFAULT;
213 module_ctx->module_hash_binary_count = MODULE_DEFAULT;
214 module_ctx->module_hash_binary_parse = MODULE_DEFAULT;
215 module_ctx->module_hash_binary_save = MODULE_DEFAULT;
216 module_ctx->module_hash_decode_potfile = MODULE_DEFAULT;
217 module_ctx->module_hash_decode_zero_hash = MODULE_DEFAULT;
218 module_ctx->module_hash_decode = module_hash_decode;
219 module_ctx->module_hash_encode_status = MODULE_DEFAULT;
220 module_ctx->module_hash_encode_potfile = MODULE_DEFAULT;
221 module_ctx->module_hash_encode = module_hash_encode;
222 module_ctx->module_hash_init_selftest = MODULE_DEFAULT;
223 module_ctx->module_hash_mode = MODULE_DEFAULT;
224 module_ctx->module_hash_category = module_hash_category;
225 module_ctx->module_hash_name = module_hash_name;
226 module_ctx->module_hashes_count_min = MODULE_DEFAULT;
227 module_ctx->module_hashes_count_max = MODULE_DEFAULT;
228 module_ctx->module_hlfmt_disable = MODULE_DEFAULT;
229 module_ctx->module_hook_extra_param_size = MODULE_DEFAULT;
230 module_ctx->module_hook_extra_param_init = MODULE_DEFAULT;
231 module_ctx->module_hook_extra_param_term = MODULE_DEFAULT;
232 module_ctx->module_hook12 = MODULE_DEFAULT;
233 module_ctx->module_hook23 = MODULE_DEFAULT;
234 module_ctx->module_hook_salt_size = MODULE_DEFAULT;
235 module_ctx->module_hook_size = MODULE_DEFAULT;
236 module_ctx->module_jit_build_options = MODULE_DEFAULT;
237 module_ctx->module_jit_cache_disable = MODULE_DEFAULT;
238 module_ctx->module_kernel_accel_max = MODULE_DEFAULT;
239 module_ctx->module_kernel_accel_min = MODULE_DEFAULT;
240 module_ctx->module_kernel_loops_max = MODULE_DEFAULT;
241 module_ctx->module_kernel_loops_min = MODULE_DEFAULT;
242 module_ctx->module_kernel_threads_max = MODULE_DEFAULT;
243 module_ctx->module_kernel_threads_min = MODULE_DEFAULT;
244 module_ctx->module_kern_type = module_kern_type;
245 module_ctx->module_kern_type_dynamic = MODULE_DEFAULT;
246 module_ctx->module_opti_type = module_opti_type;
247 module_ctx->module_opts_type = module_opts_type;
248 module_ctx->module_outfile_check_disable = MODULE_DEFAULT;
249 module_ctx->module_outfile_check_nocomp = MODULE_DEFAULT;
250 module_ctx->module_potfile_custom_check = MODULE_DEFAULT;
251 module_ctx->module_potfile_disable = MODULE_DEFAULT;
252 module_ctx->module_potfile_keep_all_hashes = MODULE_DEFAULT;
253 module_ctx->module_pwdump_column = MODULE_DEFAULT;
254 module_ctx->module_pw_max = MODULE_DEFAULT;
255 module_ctx->module_pw_min = MODULE_DEFAULT;
256 module_ctx->module_salt_max = MODULE_DEFAULT;
257 module_ctx->module_salt_min = MODULE_DEFAULT;
258 module_ctx->module_salt_type = module_salt_type;
259 module_ctx->module_separator = MODULE_DEFAULT;
260 module_ctx->module_st_hash = module_st_hash;
261 module_ctx->module_st_pass = module_st_pass;
262 module_ctx->module_tmp_size = MODULE_DEFAULT;
263 module_ctx->module_unstable_warning = MODULE_DEFAULT;
264 module_ctx->module_warmup_disable = MODULE_DEFAULT;
265 }
266