1#[allow(unused_imports)]
2#[allow(non_snake_case)]
3mod algorithms;
4
5use core::str;
6use std::collections::HashMap;
7use std::error::Error;
8use std::fs;
9
10use algorithms::*;
11
12pub fn run(config: Config) {
13 let hash_possible_algorithms = get_possible_algorithms(config);
14
15 for algorithm in hash_possible_algorithms.iter() {
16 println!("Hash: {}", algorithm.hash);
17 if algorithm.possible_algorithms.len() < 1 {
18 println!(" not found");
19 } else {
20 for alg in algorithm.possible_algorithms.iter() {
21 println!(" [+] {}", alg);
22 }
23 };
24 println!("------------------------------------------");
25 }
26}
27
28pub struct Config {
29 pub hash: String,
30 pub file: String,
31}
32
33impl Config {
34 pub fn new(hash: String, file: String) -> Config {
35 Config { hash, file }
36 }
37}
38
39struct PossibleAlgorithms {
40 pub hash: String,
41 pub possible_algorithms: Vec<String>,
42}
43
44impl PossibleAlgorithms {
45 pub fn new(hash: String, possible_algorithms: Vec<String>) -> PossibleAlgorithms {
46 PossibleAlgorithms {
47 hash,
48 possible_algorithms,
49 }
50 }
51}
52
53fn get_possible_algorithms(config: Config) -> Vec<PossibleAlgorithms> {
54 let mut possible_algorithms = vec![];
55
56 if config.hash.len() > 0 {
57 let detected_algorithms = detect_algorithms(&config.hash);
58 possible_algorithms.push(PossibleAlgorithms::new(
59 config.hash.clone(),
60 detected_algorithms,
61 ));
62 }
63
64 if config.file.len() > 0 {
65 let file_hashes = read_file_lines(config.file).unwrap();
66 for hash in file_hashes.iter() {
67 let detected_algorithms = detect_algorithms(hash);
68 possible_algorithms.push(PossibleAlgorithms::new(
69 hash.to_string(),
70 detected_algorithms,
71 ));
72 }
73 }
74
75 possible_algorithms
76}
77
78fn detect_algorithms(hash: &String) -> Vec<String> {
79 let algorithms_map: HashMap<u32, String> = create_algorithms_map();
80 let match_algorithms = run_algorithms_test(&hash);
81 let mut algorithms_name = vec![];
82
83 for algorithm in match_algorithms.iter() {
84 algorithms_name.push(algorithms_map.get(algorithm).unwrap().to_string());
85 }
86 algorithms_name
87}
88
89fn read_file_lines(file: String) -> Result<Vec<String>, Box<dyn Error>> {
90 let content = fs::read_to_string(file).unwrap();
91
92 let mut lines: Vec<String> = vec![];
93
94 for line in content.lines() {
95 lines.push(line.to_string());
96 }
97
98 Ok(lines)
99}
100
101fn run_algorithms_test(hash: &str) -> Vec<u32> {
102 let mut algorithms: Vec<u32> = vec![];
103
104 if CRC16(hash) {
105 algorithms.push(101020);
106 }
107 if CRC16CCITT(hash) {
108 algorithms.push(101040);
109 }
110 if FCS16(hash) {
111 algorithms.push(101060);
112 }
113 if ADLER32(hash) {
114 algorithms.push(102020);
115 }
116 if CRC32(hash) {
117 algorithms.push(102040);
118 }
119 if CRC32B(hash) {
120 algorithms.push(102060);
121 }
122 if XOR32(hash) {
123 algorithms.push(102080);
124 }
125 if GHash325(hash) {
126 algorithms.push(103020);
127 }
128 if GHash323(hash) {
129 algorithms.push(103040);
130 }
131 if DESUnix(hash) {
132 algorithms.push(104020);
133 }
134 if MySQL(hash) {
135 algorithms.push(105020);
136 }
137 if MD5Middle(hash) {
138 algorithms.push(105040);
139 }
140 if MD5Half(hash) {
141 algorithms.push(105060);
142 }
143 if MD5(hash) {
144 algorithms.push(106020);
145 }
146 if DomainCachedCredentials(hash) {
147 algorithms.push(106025);
148 }
149 if RAdminv2x(hash) {
150 algorithms.push(106027);
151 }
152 if NTLM(hash) {
153 algorithms.push(106029);
154 }
155 if MD4(hash) {
156 algorithms.push(106040);
157 }
158 if MD2(hash) {
159 algorithms.push(106060);
160 }
161 if MD5HMAC(hash) {
162 algorithms.push(106080);
163 }
164 if MD4HMAC(hash) {
165 algorithms.push(106100);
166 }
167 if MD2HMAC(hash) {
168 algorithms.push(106120);
169 }
170 if MD5HMACWordpress(hash) {
171 algorithms.push(106140);
172 }
173 if Haval128(hash) {
174 algorithms.push(106160);
175 }
176 if Haval128HMAC(hash) {
177 algorithms.push(106165);
178 }
179 if RipeMD128(hash) {
180 algorithms.push(106180);
181 }
182 if RipeMD128HMAC(hash) {
183 algorithms.push(106185);
184 }
185 if SNEFRU128(hash) {
186 algorithms.push(106200);
187 }
188 if SNEFRU128HMAC(hash) {
189 algorithms.push(106205);
190 }
191 if Tiger128(hash) {
192 algorithms.push(106220);
193 }
194 if Tiger128HMAC(hash) {
195 algorithms.push(106225);
196 }
197 if md5passsalt(hash) {
198 algorithms.push(106240);
199 }
200 if md5saltmd5pass(hash) {
201 algorithms.push(106260);
202 }
203 if md5saltpass(hash) {
204 algorithms.push(106280);
205 }
206 if md5saltpasssalt(hash) {
207 algorithms.push(106300);
208 }
209 if md5saltpassusername(hash) {
210 algorithms.push(106320);
211 }
212 if md5saltmd5pass(hash) {
213 algorithms.push(106340);
214 }
215 if md5saltmd5passsalt(hash) {
216 algorithms.push(106360);
217 }
218 if md5saltmd5passsalt1(hash) {
219 algorithms.push(106380);
220 }
221 if md5saltmd5saltpass2(hash) {
222 algorithms.push(106400);
223 }
224 if md5saltmd5md5passsalt(hash) {
225 algorithms.push(106420);
226 }
227 if md5username0pass(hash) {
228 algorithms.push(106440);
229 }
230 if md5usernameLFpass(hash) {
231 algorithms.push(106460);
232 }
233 if md5usernamemd5passsalt(hash) {
234 algorithms.push(106480);
235 }
236 if md5md5pass(hash) {
237 algorithms.push(106500);
238 }
239 if md5md5passsalt(hash) {
240 algorithms.push(106520);
241 }
242 if md5md5passmd5salt(hash) {
243 algorithms.push(106540);
244 }
245 if md5md5saltpass(hash) {
246 algorithms.push(106560);
247 }
248 if md5md5saltmd5pass(hash) {
249 algorithms.push(106580);
250 }
251 if md5md5usernamepasssalt(hash) {
252 algorithms.push(106600);
253 }
254 if md5md5md5pass(hash) {
255 algorithms.push(106620);
256 }
257 if md5md5md5md5pass(hash) {
258 algorithms.push(106640);
259 }
260 if md5md5md5md5md5pass(hash) {
261 algorithms.push(106660);
262 }
263 if md5sha1pass(hash) {
264 algorithms.push(106680);
265 }
266 if md5sha1md5pass(hash) {
267 algorithms.push(106700);
268 }
269 if md5sha1md5sha1pass(hash) {
270 algorithms.push(106720);
271 }
272 if md5strtouppermd5pass(hash) {
273 algorithms.push(106740);
274 }
275 if MD5Wordpress(hash) {
276 algorithms.push(107020);
277 }
278 if MD5phpBB3(hash) {
279 algorithms.push(107040);
280 }
281 if MD5Unix(hash) {
282 algorithms.push(107060);
283 }
284 if LineageIIC4(hash) {
285 algorithms.push(107080);
286 }
287 if MD5APR(hash) {
288 algorithms.push(108020);
289 }
290 if SHA1(hash) {
291 algorithms.push(109020);
292 }
293 if MySQL5(hash) {
294 algorithms.push(109040);
295 }
296 if MySQL160bit(hash) {
297 algorithms.push(109060);
298 }
299 if Tiger160(hash) {
300 algorithms.push(109080);
301 }
302 if Haval160(hash) {
303 algorithms.push(109100);
304 }
305 if RipeMD160(hash) {
306 algorithms.push(109120);
307 }
308 if SHA1HMAC(hash) {
309 algorithms.push(109140);
310 }
311 if Tiger160HMAC(hash) {
312 algorithms.push(109160);
313 }
314 if RipeMD160HMAC(hash) {
315 algorithms.push(109180);
316 }
317 if Haval160HMAC(hash) {
318 algorithms.push(109200);
319 }
320 if SHA1MaNGOS(hash) {
321 algorithms.push(109220);
322 }
323 if SHA1MaNGOS2(hash) {
324 algorithms.push(109240);
325 }
326 if sha1passsalt(hash) {
327 algorithms.push(109260);
328 }
329 if sha1saltpass(hash) {
330 algorithms.push(109280);
331 }
332 if sha1saltmd5pass(hash) {
333 algorithms.push(109300);
334 }
335 if sha1saltmd5passsalt(hash) {
336 algorithms.push(109320);
337 }
338 if sha1saltsha1pass(hash) {
339 algorithms.push(109340);
340 }
341 if sha1saltsha1saltsha1pass(hash) {
342 algorithms.push(109360);
343 }
344 if sha1usernamepass(hash) {
345 algorithms.push(109380);
346 }
347 if sha1usernamepasssalt(hash) {
348 algorithms.push(109400);
349 }
350 if sha1md5passsalt(hash) {
351 algorithms.push(109440);
352 }
353 if sha1md5sha1pass(hash) {
354 algorithms.push(109460);
355 }
356 if sha1sha1pass(hash) {
357 algorithms.push(109480);
358 }
359 if sha1sha1passsalt(hash) {
360 algorithms.push(109500);
361 }
362 if sha1sha1passsubstrpass03(hash) {
363 algorithms.push(109520);
364 }
365 if sha1sha1saltpass(hash) {
366 algorithms.push(109540);
367 }
368 if sha1sha1sha1pass(hash) {
369 algorithms.push(109560);
370 }
371 if sha1strtolowerusernamepass(hash) {
372 algorithms.push(109580);
373 }
374 if Tiger192(hash) {
375 algorithms.push(110020);
376 }
377 if Haval192(hash) {
378 algorithms.push(110040);
379 }
380 if Tiger192HMAC(hash) {
381 algorithms.push(110060);
382 }
383 if Haval192HMAC(hash) {
384 algorithms.push(110080);
385 }
386 if MD5passsaltjoomla1(hash) {
387 algorithms.push(112020);
388 }
389 if SHA1Django(hash) {
390 algorithms.push(113020);
391 }
392 if SHA224(hash) {
393 algorithms.push(114020);
394 }
395 if Haval224(hash) {
396 algorithms.push(114040);
397 }
398 if SHA224HMAC(hash) {
399 algorithms.push(114060);
400 }
401 if Haval224HMAC(hash) {
402 algorithms.push(114080);
403 }
404 if SHA256(hash) {
405 algorithms.push(115020);
406 }
407 if Haval256(hash) {
408 algorithms.push(115040);
409 }
410 if GOSTR341194(hash) {
411 algorithms.push(115060);
412 }
413 if RipeMD256(hash) {
414 algorithms.push(115080);
415 }
416 if SNEFRU256(hash) {
417 algorithms.push(115100);
418 }
419 if SHA256HMAC(hash) {
420 algorithms.push(115120);
421 }
422 if Haval256HMAC(hash) {
423 algorithms.push(115140);
424 }
425 if RipeMD256HMAC(hash) {
426 algorithms.push(115160);
427 }
428 if SNEFRU256HMAC(hash) {
429 algorithms.push(115180);
430 }
431 if SHA256md5pass(hash) {
432 algorithms.push(115200);
433 }
434 if SHA256sha1pass(hash) {
435 algorithms.push(115220);
436 }
437 if MD5passsaltjoomla2(hash) {
438 algorithms.push(116020);
439 }
440 if SAM(hash) {
441 algorithms.push(116040);
442 }
443 if SHA256Django(hash) {
444 algorithms.push(117020);
445 }
446 if RipeMD320(hash) {
447 algorithms.push(118020);
448 }
449 if RipeMD320HMAC(hash) {
450 algorithms.push(118040);
451 }
452 if SHA384(hash) {
453 algorithms.push(119020);
454 }
455 if SHA384HMAC(hash) {
456 algorithms.push(119040);
457 }
458 if SHA256s(hash) {
459 algorithms.push(120020);
460 }
461 if SHA384Django(hash) {
462 algorithms.push(121020);
463 }
464 if SHA512(hash) {
465 algorithms.push(122020);
466 }
467 if Whirlpool(hash) {
468 algorithms.push(122040);
469 }
470 if SHA512HMAC(hash) {
471 algorithms.push(122060);
472 }
473 if WhirlpoolHMAC(hash) {
474 algorithms.push(122080);
475 }
476 if sha1md5pass(hash) {
477 algorithms.push(1094202);
478 }
479
480 algorithms
481}
482
483fn create_algorithms_map() -> HashMap<u32, String> {
484 let mut algorithms = HashMap::new();
485
486 algorithms.insert(102020, "ADLER-32".to_string());
487 algorithms.insert(101020, "CRC-16".to_string());
488 algorithms.insert(101040, "CRC-16-CCITT".to_string());
489 algorithms.insert(101060, "FCS-16".to_string());
490 algorithms.insert(102020, "ADLER-32".to_string());
491 algorithms.insert(102040, "CRC-32".to_string());
492 algorithms.insert(102060, "CRC-32B".to_string());
493 algorithms.insert(102080, "XOR-32".to_string());
494 algorithms.insert(103020, "GHash-32-5".to_string());
495 algorithms.insert(103040, "GHash-32-3".to_string());
496 algorithms.insert(104020, "DES(Unix)".to_string());
497 algorithms.insert(105020, "MySQL".to_string());
498 algorithms.insert(105040, "MD5(Middle)".to_string());
499 algorithms.insert(105060, "MD5(Half)".to_string());
500 algorithms.insert(106020, "MD5".to_string());
501 algorithms.insert(
502 106025,
503 "Domain Cached Credentials - MD4(MD4(($pass)).(strtolower($username)))".to_string(),
504 );
505 algorithms.insert(106027, "RAdmin v2.x".to_string());
506 algorithms.insert(106029, "NTLM".to_string());
507 algorithms.insert(106040, "MD4".to_string());
508 algorithms.insert(106060, "MD2".to_string());
509 algorithms.insert(106080, "MD5(HMAC)".to_string());
510 algorithms.insert(106100, "MD4(HMAC)".to_string());
511 algorithms.insert(106120, "MD2(HMAC)".to_string());
512 algorithms.insert(106140, "MD5(HMAC(Wordpress))".to_string());
513 algorithms.insert(106160, "Haval-128".to_string());
514 algorithms.insert(106165, "Haval-128(HMAC)".to_string());
515 algorithms.insert(106180, "RipeMD-128".to_string());
516 algorithms.insert(106185, "RipeMD-128(HMAC)".to_string());
517 algorithms.insert(106200, "SNEFRU-128".to_string());
518 algorithms.insert(106205, "SNEFRU-128(HMAC)".to_string());
519 algorithms.insert(106220, "Tiger-128".to_string());
520 algorithms.insert(106225, "Tiger-128(HMAC)".to_string());
521 algorithms.insert(106240, "md5($pass.$salt)".to_string());
522 algorithms.insert(106260, "md5($salt.'-'.md5($pass))".to_string());
523 algorithms.insert(106280, "md5($salt.$pass)".to_string());
524 algorithms.insert(106300, "md5($salt.$pass.$salt)".to_string());
525 algorithms.insert(106320, "md5($salt.$pass.$username)".to_string());
526 algorithms.insert(106340, "md5($salt.md5($pass))".to_string());
527 algorithms.insert(106360, "md5($salt.md5($pass).$salt)".to_string());
528 algorithms.insert(106380, "md5($salt.md5($pass.$salt))".to_string());
529 algorithms.insert(106400, "md5($salt.md5($salt.$pass))".to_string());
530 algorithms.insert(106420, "md5($salt.md5(md5($pass).$salt))".to_string());
531 algorithms.insert(106440, "md5($username.0.$pass)".to_string());
532 algorithms.insert(106460, "md5($username.LF.$pass)".to_string());
533 algorithms.insert(106480, "md5($username.md5($pass).$salt)".to_string());
534 algorithms.insert(106500, "md5(md5($pass))".to_string());
535 algorithms.insert(106520, "md5(md5($pass).$salt)".to_string());
536 algorithms.insert(106540, "md5(md5($pass).md5($salt))".to_string());
537 algorithms.insert(106560, "md5(md5($salt).$pass)".to_string());
538 algorithms.insert(106580, "md5(md5($salt).md5($pass))".to_string());
539 algorithms.insert(106600, "md5(md5($username.$pass).$salt)".to_string());
540 algorithms.insert(106620, "md5(md5(md5($pass)))".to_string());
541 algorithms.insert(106640, "md5(md5(md5(md5($pass))))".to_string());
542 algorithms.insert(106660, "md5(md5(md5(md5(md5($pass)))))".to_string());
543 algorithms.insert(106680, "md5(sha1($pass))".to_string());
544 algorithms.insert(106700, "md5(sha1(md5($pass)))".to_string());
545 algorithms.insert(106720, "md5(sha1(md5(sha1($pass))))".to_string());
546 algorithms.insert(106740, "md5(strtoupper(md5($pass)))".to_string());
547 algorithms.insert(107020, "MD5(Wordpress)".to_string());
548 algorithms.insert(107040, "MD5(phpBB3)".to_string());
549 algorithms.insert(107060, "MD5(Unix)".to_string());
550 algorithms.insert(107080, "Lineage II C4".to_string());
551 algorithms.insert(108020, "MD5(APR)".to_string());
552 algorithms.insert(109020, "SHA-1".to_string());
553 algorithms.insert(109040, "MySQL5 - SHA-1(SHA-1($pass))".to_string());
554 algorithms.insert(109060, "MySQL 160bit - SHA-1(SHA-1($pass))".to_string());
555 algorithms.insert(109080, "Tiger-160".to_string());
556 algorithms.insert(109100, "Haval-160".to_string());
557 algorithms.insert(109120, "RipeMD-160".to_string());
558 algorithms.insert(109140, "SHA-1(HMAC)".to_string());
559 algorithms.insert(109160, "Tiger-160(HMAC)".to_string());
560 algorithms.insert(109180, "RipeMD-160(HMAC)".to_string());
561 algorithms.insert(109200, "Haval-160(HMAC)".to_string());
562 algorithms.insert(109220, "SHA-1(MaNGOS)".to_string());
563 algorithms.insert(109240, "SHA-1(MaNGOS2)".to_string());
564 algorithms.insert(109260, "sha1($pass.$salt)".to_string());
565 algorithms.insert(109280, "sha1($salt.$pass)".to_string());
566 algorithms.insert(109300, "sha1($salt.md5($pass))".to_string());
567 algorithms.insert(109320, "sha1($salt.md5($pass).$salt)".to_string());
568 algorithms.insert(109340, "sha1($salt.sha1($pass))".to_string());
569 algorithms.insert(109360, "sha1($salt.sha1($salt.sha1($pass)))".to_string());
570 algorithms.insert(109380, "sha1($username.$pass)".to_string());
571 algorithms.insert(109400, "sha1($username.$pass.$salt)".to_string());
572 algorithms.insert(109440, "sha1(md5($pass).$salt)".to_string());
573 algorithms.insert(109460, "sha1(md5(sha1($pass)))".to_string());
574 algorithms.insert(109480, "sha1(sha1($pass))".to_string());
575 algorithms.insert(109500, "sha1(sha1($pass).$salt)".to_string());
576 algorithms.insert(109520, "sha1(sha1($pass).substr($pass,0,3))".to_string());
577 algorithms.insert(109540, "sha1(sha1($salt.$pass))".to_string());
578 algorithms.insert(109560, "sha1(sha1(sha1($pass)))".to_string());
579 algorithms.insert(109580, "sha1(strtolower($username).$pass)".to_string());
580 algorithms.insert(110020, "Tiger-192".to_string());
581 algorithms.insert(110040, "Haval-192".to_string());
582 algorithms.insert(110060, "Tiger-192(HMAC)".to_string());
583 algorithms.insert(110080, "Haval-192(HMAC)".to_string());
584 algorithms.insert(112020, "md5($pass.$salt) - Joomla".to_string());
585 algorithms.insert(113020, "SHA-1(Django)".to_string());
586 algorithms.insert(114020, "SHA-224".to_string());
587 algorithms.insert(114040, "Haval-224".to_string());
588 algorithms.insert(114060, "SHA-224(HMAC)".to_string());
589 algorithms.insert(114080, "Haval-224(HMAC)".to_string());
590 algorithms.insert(115020, "SHA-256".to_string());
591 algorithms.insert(115040, "Haval-256".to_string());
592 algorithms.insert(115060, "GOST R 34.11-94".to_string());
593 algorithms.insert(115080, "RipeMD-256".to_string());
594 algorithms.insert(115100, "SNEFRU-256".to_string());
595 algorithms.insert(115120, "SHA-256(HMAC)".to_string());
596 algorithms.insert(115140, "Haval-256(HMAC)".to_string());
597 algorithms.insert(115160, "RipeMD-256(HMAC)".to_string());
598 algorithms.insert(115180, "SNEFRU-256(HMAC)".to_string());
599 algorithms.insert(115200, "SHA-256(md5($pass))".to_string());
600 algorithms.insert(115220, "SHA-256(sha1($pass))".to_string());
601 algorithms.insert(116020, "md5($pass.$salt) - Joomla".to_string());
602 algorithms.insert(116040, "SAM - (LM_hash:NT_hash)".to_string());
603 algorithms.insert(117020, "SHA-256(Django)".to_string());
604 algorithms.insert(118020, "RipeMD-320".to_string());
605 algorithms.insert(118040, "RipeMD-320(HMAC)".to_string());
606 algorithms.insert(119020, "SHA-384".to_string());
607 algorithms.insert(119040, "SHA-384(HMAC)".to_string());
608 algorithms.insert(120020, "SHA-256".to_string());
609 algorithms.insert(121020, "SHA-384(Django)".to_string());
610 algorithms.insert(122020, "SHA-512".to_string());
611 algorithms.insert(122040, "Whirlpool".to_string());
612 algorithms.insert(122060, "SHA-512(HMAC)".to_string());
613 algorithms.insert(122080, "Whirlpool(HMAC)".to_string());
614 algorithms.insert(1094202, "sha1(md5($pass))".to_string());
615
616 algorithms
617}
618
619#[cfg(test)]
620mod tests {
621 use super::*;
622
623 #[test]
624 fn create_map() {
625 let key = 1094202;
626 let map = create_algorithms_map();
627
628 assert_eq!("sha1(md5($pass))", map.get(&key).unwrap());
629 }
630}