4 ## Author......: Jens Steube <jens.steube@gmail.com>
10 use Digest
::MD4 qw
(md4 md4_hex
);
11 use Digest
::MD5 qw
(md5 md5_hex
);
12 use Digest
::SHA qw
(sha1 sha256 sha384 sha512 sha1_hex sha256_hex sha384_hex sha512_hex
);
13 use Digest
::HMAC qw
(hmac hmac_hex
);
14 use Digest
::Keccak qw
(keccak_256_hex
);
15 use Crypt
::MySQL qw
(password41
);
16 use Digest
::GOST qw
(gost gost_hex
);
17 use Digest
::HMAC_MD5 qw
(hmac_md5
);
18 use Digest
::CRC qw
(crc32
);
21 use Crypt
::ECB qw
(encrypt
);
23 use Crypt
::Eksblowfish
::Bcrypt qw
(bcrypt en_base64
);
24 use Crypt
::Digest
::RIPEMD160 qw
(ripemd160_hex
);
25 use Crypt
::Digest
::Whirlpool qw
(whirlpool_hex
);
27 use Crypt
::ScryptKDF qw
(scrypt_hash scrypt_b64
);
31 use Crypt
::UnixCrypt_XS qw
(crypt_rounds fold_password base64_to_int24 block_to_base64 int24_to_base64
);
33 use Authen
::Passphrase
::NTHash
;
34 use Authen
::Passphrase
::MySQL323
;
35 use Authen
::Passphrase
::PHPass
;
36 use Authen
::Passphrase
::LANManager
;
38 use POSIX qw
(strftime
);
40 use Net
::DNS
::RR
::NSEC3
;
41 use Convert
::EBCDIC qw
(ascii2ebcdic
);
42 use Digest
::SipHash qw
/siphash/;
44 my $hashcat = "./hashcat";
48 my @modes = (0, 10, 11, 12, 20, 21, 22, 23, 30, 40, 50, 60, 100, 101, 110, 111, 112, 120, 121, 122, 125, 130, 131, 132, 133, 140, 141, 150, 160, 200, 300, 400, 500, 900, 1000, 1100, 1400, 1410, 1420, 1430, 1440, 1441, 1450, 1460, 1500, 1600, 1700, 1710, 1711, 1720, 1730, 1740, 1722, 1731, 1750, 1760, 1800, 2100, 2400, 2410, 2500, 2600, 2611, 2612, 2711, 2811, 3000, 3100, 3200, 3710, 3711, 3300, 3500, 3610, 3720, 3800, 3910, 4010, 4110, 4210, 4300, 4400, 4500, 4600, 4700, 4800, 4900, 5000, 5100, 5300, 5400, 5500, 5600, 5700, 5800, 6000, 6100, 6300, 6400, 6500, 6600, 6700, 6800, 6900, 7100, 7200, 7300, 7400, 7500, 7600, 7700, 7800, 7900, 8000, 8100, 8200, 8300, 8400, 8500, 8600, 8700, 8900, 9100, 9200, 9300, 9400, 9500, 9600, 9700, 9800, 9900, 10000, 10100, 10200, 10300, 10400, 10500, 10600, 10700, 10800, 10900, 11000, 11100, 11200, 11300, 11400, 11500, 11600, 11900, 12000, 12100, 12200, 12300, 12400, 12600, 12700, 12800, 12900, 13000, 13100, 13200, 13300, 13400, 13500, 13600, 13800);
50 my %is_unicode = map { $_ => 1 } qw(30 40 130 131 132 133 140 141 1000 1100 1430 1440 1441 1730 1740 1731 5500 5600 8000 9400 9500 9600 9700 9800 11600 13500 13800);
51 my %less_fifteen = map { $_ => 1 } qw(500 1600 1800 2400 2410 3200 6300 7400 10500 10700);
52 my %allow_long_salt = map { $_ => 1 } qw(2500 5500 5600 7100 7200 7300 9400 9500 9600 9700 9800 10400 10500 10600 10700 1100 11000 11200 11300 11400 11600 12600 13500 13800);
54 my @lotus_magic_table =
56 0xbd, 0x56, 0xea, 0xf2, 0xa2, 0xf1, 0xac, 0x2a,
57 0xb0, 0x93, 0xd1, 0x9c, 0x1b, 0x33, 0xfd, 0xd0,
58 0x30, 0x04, 0xb6, 0xdc, 0x7d, 0xdf, 0x32, 0x4b,
59 0xf7, 0xcb, 0x45, 0x9b, 0x31, 0xbb, 0x21, 0x5a,
60 0x41, 0x9f, 0xe1, 0xd9, 0x4a, 0x4d, 0x9e, 0xda,
61 0xa0, 0x68, 0x2c, 0xc3, 0x27, 0x5f, 0x80, 0x36,
62 0x3e, 0xee, 0xfb, 0x95, 0x1a, 0xfe, 0xce, 0xa8,
63 0x34, 0xa9, 0x13, 0xf0, 0xa6, 0x3f, 0xd8, 0x0c,
64 0x78, 0x24, 0xaf, 0x23, 0x52, 0xc1, 0x67, 0x17,
65 0xf5, 0x66, 0x90, 0xe7, 0xe8, 0x07, 0xb8, 0x60,
66 0x48, 0xe6, 0x1e, 0x53, 0xf3, 0x92, 0xa4, 0x72,
67 0x8c, 0x08, 0x15, 0x6e, 0x86, 0x00, 0x84, 0xfa,
68 0xf4, 0x7f, 0x8a, 0x42, 0x19, 0xf6, 0xdb, 0xcd,
69 0x14, 0x8d, 0x50, 0x12, 0xba, 0x3c, 0x06, 0x4e,
70 0xec, 0xb3, 0x35, 0x11, 0xa1, 0x88, 0x8e, 0x2b,
71 0x94, 0x99, 0xb7, 0x71, 0x74, 0xd3, 0xe4, 0xbf,
72 0x3a, 0xde, 0x96, 0x0e, 0xbc, 0x0a, 0xed, 0x77,
73 0xfc, 0x37, 0x6b, 0x03, 0x79, 0x89, 0x62, 0xc6,
74 0xd7, 0xc0, 0xd2, 0x7c, 0x6a, 0x8b, 0x22, 0xa3,
75 0x5b, 0x05, 0x5d, 0x02, 0x75, 0xd5, 0x61, 0xe3,
76 0x18, 0x8f, 0x55, 0x51, 0xad, 0x1f, 0x0b, 0x5e,
77 0x85, 0xe5, 0xc2, 0x57, 0x63, 0xca, 0x3d, 0x6c,
78 0xb4, 0xc5, 0xcc, 0x70, 0xb2, 0x91, 0x59, 0x0d,
79 0x47, 0x20, 0xc8, 0x4f, 0x58, 0xe0, 0x01, 0xe2,
80 0x16, 0x38, 0xc4, 0x6f, 0x3b, 0x0f, 0x65, 0x46,
81 0xbe, 0x7e, 0x2d, 0x7b, 0x82, 0xf9, 0x40, 0xb5,
82 0x1d, 0x73, 0xf8, 0xeb, 0x26, 0xc7, 0x87, 0x97,
83 0x25, 0x54, 0xb1, 0x28, 0xaa, 0x98, 0x9d, 0xa5,
84 0x64, 0x6d, 0x7a, 0xd4, 0x10, 0x81, 0x44, 0xef,
85 0x49, 0xd6, 0xae, 0x2e, 0xdd, 0x76, 0x5c, 0x2f,
86 0xa7, 0x1c, 0xc9, 0x09, 0x69, 0x9a, 0x83, 0xcf,
87 0x29, 0x39, 0xb9, 0xe9, 0x4c, 0xff, 0x43, 0xab
92 0x28, 0xbf, 0x4e, 0x5e, 0x4e, 0x75, 0x8a, 0x41,
93 0x64, 0x00, 0x4e, 0x56, 0xff, 0xfa, 0x01, 0x08,
94 0x2e, 0x2e, 0x00, 0xb6, 0xd0, 0x68, 0x3e, 0x80,
95 0x2f, 0x0c, 0xa9, 0xfe, 0x64, 0x53, 0x69, 0x7a
98 my $CISCO_BASE64_MAPPING = {'A', '.', 'B', '/', 'C', '0', 'D', '1', 'E', '2', 'F', '3', 'G', '4', 'H', '5', 'I', '6', 'J', '7', 'K', '8', 'L', '9', 'M', 'A', 'N', 'B', 'O', 'C', 'P', 'D', 'Q', 'E', 'R', 'F', 'S', 'G', 'T', 'H', 'U', 'I', 'V', 'J', 'W', 'K', 'X', 'L', 'Y', 'M', 'Z', 'N', 'a', 'O', 'b', 'P', 'c', 'Q', 'd', 'R', 'e', 'S', 'f', 'T', 'g', 'U', 'h', 'V', 'i', 'W', 'j', 'X', 'k', 'Y', 'l', 'Z', 'm', 'a', 'n', 'b', 'o', 'c', 'p', 'd', 'q', 'e', 'r', 'f', 's', 'g', 't', 'h', 'u', 'i', 'v', 'j', 'w', 'k', 'x', 'l', 'y', 'm', 'z', 'n', '0', 'o', '1', 'p', '2', 'q', '3', 'r', '4', 's', '5', 't', '6', 'u', '7', 'v', '8', 'w', '9', 'x', '+', 'y', '/', 'z'};
100 if (scalar @ARGV < 1)
111 if ($type ne "verify")
113 if (scalar @ARGV > 1)
118 elsif (scalar @ARGV == 1)
128 if ($type eq "single")
132 elsif ($type eq "passthrough")
143 if (scalar @ARGV != 4)
148 my $mode = shift @ARGV;
149 my $hash_file = shift @ARGV;
150 my $in_file = shift @ARGV;
151 my $out_file = shift @ARGV;
155 open (IN
, "<", $hash_file) or die ("$hash_file: $!\n");
157 # clever ? the resulting database could be huge
158 # but we need some way to map lines in hashfile w/ cracks
159 # maybe rli2 way would be more clever (needs sorted input)
161 while (my $line = <IN
>)
163 $line =~ s/[\n\r]*$//;
165 $db->{$line} = undef;
170 verify
($mode, $db, $in_file, $out_file);
178 my $out_file = shift;
197 open (IN
, "<", $in_file) or die ("$in_file: $!\n");
198 open (OUT
, ">", $out_file) or die ("$out_file: $!\n");
202 my $base64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
203 my $itoa64_1 = "./0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
204 my $itoa64_2 = "./ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
206 while (my $line = <IN
>)
213 # remember always do "exists ($db->{$hash_in})" checks as soon as possible and don't forget it
216 if ($mode == 0 || $mode == 100 || $mode == 101 || $mode == 133 || $mode == 200 || $mode == 300 || $mode == 900 || $mode == 1000 || $mode == 1400 || $mode == 1700 || $mode == 2400 || $mode == 2600 || $mode == 3000 || $mode == 3500 || $mode == 4300 || $mode == 4400 || $mode == 4500 || $mode == 4600 || $mode == 4700 || $mode == 5000 || $mode == 5100 || $mode == 5700 || $mode == 6000 || $mode == 6100 || $mode == 6900 || $mode == 8600 || $mode == 9900 || $mode == 10800 || $mode == 11500)
218 my $index = index ($line, ":");
222 $hash_in = substr ($line, 0, $index);
224 next unless (exists ($db->{$hash_in}) and (! defined ($db->{$hash_in})));
226 $word = substr ($line, $index + 1);
229 elsif ($mode == 10 || $mode == 11 || $mode == 12 || $mode == 20 || $mode == 21 || $mode == 22 || $mode == 23 || $mode == 30 || $mode == 40 || $mode == 50 || $mode == 60 || $mode == 110 || $mode == 112 || $mode == 120 || $mode == 121 || $mode == 130 || $mode == 140 || $mode == 150 || $mode == 160 || $mode == 1100 || $mode == 1410 || $mode == 1420 || $mode == 1430 || $mode == 1440 || $mode == 1450 || $mode == 1460 || $mode == 1710 || $mode == 1720 || $mode == 1730 || $mode == 1740 || $mode == 1750 || $mode == 1760 || $mode == 2410 || $mode == 2611 || $mode == 2711 || $mode == 2811 || $mode == 3100 || $mode == 3610 || $mode == 3710 || $mode == 3720 || $mode == 3800 || $mode == 3910 || $mode == 4010 || $mode == 4110 || $mode == 4210 || $mode == 4900 || $mode == 5800 || $mode == 7600 || $mode == 8400 || $mode == 11000 || $mode == 12600 || $mode == 13500 || $mode == 13800)
232 my $index1 = index ($line, ":");
236 $hash_in = substr ($line, 0, $index1);
238 # identify lenghts of both salt and plain
240 my $salt_plain = substr ($line, $index1 + 1);
242 my $num_cols = () = $salt_plain =~ /:/g;
251 foreach (my $i = 0; $i < $num_cols; $i++)
253 $index2 = index ($salt_plain, ":", $start);
257 $start = $index2 + 1;
259 $salt = substr ($salt_plain, 0, $index2);
260 $word = substr ($salt_plain, $index2 + 1);
262 # can't be true w/ wrong $hash:$salt, otherwise the
263 # algo must have many collisions
265 if (exists ($db->{$hash_in . ":" . $salt}))
267 $hash_in = $hash_in . ":" . $salt;
273 next unless ($matched); # therefore: true == exists ($db->{$hash_in}
274 next unless (! defined ($db->{$hash_in}));
277 elsif ($mode == 2100)
280 my $index1 = index ($line, "\$DCC2\$");
282 next if $index1 != 0;
285 my $index2 = index ($line, "#", $index1 + 1);
289 $iter = substr ($line, $index1 + 6, $index2 - $index1 - 6);
292 $index1 = index ($line, "#");
296 $hash_in = substr ($line, 0, $index1 + 1);
298 # identify lenghts of both salt and plain
300 my $salt_plain = substr ($line, $index2 + 1);
302 my $num_cols = () = $salt_plain =~ /:/g;
312 foreach (my $i = 0; $i < $num_cols; $i++)
314 $index2 = index ($salt_plain, ":", $start);
318 $start = $index2 + 1;
320 $index3 = rindex ($salt_plain, "#", $index2);
322 $raw_hash = substr ($salt_plain, $index3 + 1, $index2 - $index3 - 1);
323 $salt = substr ($salt_plain, 0, $index3);
324 $word = substr ($salt_plain, $index2 + 1);
326 if (exists ($db->{$hash_in . $salt . "#" .$raw_hash}))
328 $hash_in = $hash_in . $salt . "#" . $raw_hash;
334 next unless ($matched); # therefore: true == exists ($db->{$hash_in}
335 next unless (! defined ($db->{$hash_in}));
337 # salt:hash guaranteed only : because of hex salt
338 elsif ($mode == 7300)
340 # split hash and plain
341 my $index1 = index ($line, ":");
345 $salt = substr ($line, 0, $index1);
347 $salt = pack ("H*", $salt);
349 my $rest = substr ($line, $index1 + 1);
351 my $index2 = index ($rest, ":");
355 $hash_in = substr ($rest, 0, $index2);
357 $word = substr ($rest, $index2 + 1);
359 next unless (exists ($db->{$salt . ":" . $hash_in}) and (! defined ($db->{$hash_in})));
362 elsif ($mode == 8100)
364 # split hash and plain
365 $salt = substr ($line, 1, 8);
367 my $rest = substr ($line, 1 + 8);
369 my $index2 = index ($rest, ":");
373 $hash_in = substr ($rest, 0, $index2);
375 $word = substr ($rest, $index2 + 1);
377 next unless (exists ($db->{"1" . $salt . $hash_in}) and (! defined ($db->{$hash_in})));
379 # base64 and salt embedded SSHA1, salt length = total lenght - 20
382 # split hash and plain
383 my $index = index ($line, ":");
387 $hash_in = substr ($line, 0, $index);
388 $word = substr ($line, $index + 1);
390 next unless (exists ($db->{$hash_in}) and (! defined ($db->{$hash_in})));
393 my $plain_base64 = substr ($hash_in, 6);
395 # base64 decode to extract salt
396 my $decoded = decode_base64
($plain_base64);
398 $salt = substr ($decoded, 20);
400 # base64 and salt embedded SSHA512, salt length = total length - 64
401 elsif ($mode == 1711)
403 # split hash and plain
404 my $index = index ($line, ":");
408 $hash_in = substr ($line, 0, $index);
409 $word = substr ($line, $index + 1);
411 next unless (exists ($db->{$hash_in}) and (! defined ($db->{$hash_in})));
414 my $plain_base64 = substr ($hash_in, 9);
416 # base64 decode to extract salt
417 my $decoded = decode_base64
($plain_base64);
419 $salt = substr ($decoded, 64);
421 # OSX (first 8 hex chars is salt)
422 # ArubaOS (the signature gets added in gen_hash)
423 elsif ($mode == 122 || $mode == 1722 || $mode == 125)
425 my $index = index ($line, ":");
429 $hash_in = substr ($line, 0, $index);
430 $word = substr ($line, $index + 1);
432 next unless (exists ($db->{$hash_in}) and (! defined ($db->{$hash_in})));
434 $salt = substr ($hash_in, 0, 8);
436 # MSSQL (2000, 2005 AND 2012), salt after version number
437 elsif ($mode == 131 || $mode == 132 || $mode == 1731)
439 my $index = index ($line, ":");
443 $hash_in = substr ($line, 0, $index);
444 $word = substr ($line, $index + 1);
446 next unless (exists ($db->{$hash_in}) and (! defined ($db->{$hash_in})));
448 $salt = substr ($hash_in, 6, 8);
451 elsif ($mode == 8000)
453 my $index = index ($line, ":");
457 $hash_in = substr ($line, 0, $index);
458 $word = substr ($line, $index + 1);
460 next unless (exists ($db->{$hash_in}) and (! defined ($db->{$hash_in})));
462 $salt = substr ($hash_in, 6, 16);
465 elsif ($mode == 141 || $mode == 1441)
467 my $index1 = index ($line, ":");
471 $hash_in = substr ($line, 0, $index1);
472 $word = substr ($line, $index1 + 1);
474 next unless (exists ($db->{$hash_in}) and (! defined ($db->{$hash_in})));
476 my $index2 = index ($line, "*", 14);
478 #extract salt from base64
479 my $plain_base64 = substr ($hash_in, 14, $index2 - 14);
481 $salt = decode_base64
($plain_base64);
483 # phpass (first 8 after $P$/$H$ -- or $S$ with drupal7)
484 elsif ($mode == 400 || $mode == 7900)
486 my $index = index ($line, ":");
490 $hash_in = substr ($line, 0, $index);
491 $word = substr ($line, $index + 1);
493 next unless (exists ($db->{$hash_in}) and (! defined ($db->{$hash_in})));
495 $salt = substr ($hash_in, 4, 8);
497 # iterations = 2 ^ cost (where cost == $iter)
498 $iter = index ($itoa64_1, substr ($hash_in, 3, 1));
500 # $something$[rounds=iter$]salt$ (get last $, then check iter)
501 elsif ($mode == 500 || $mode == 1600 || $mode == 1800 || $mode == 3300 || $mode == 7400)
503 my $index1 = index ($line, ":", 30);
507 $hash_in = substr ($line, 0, $index1);
508 $word = substr ($line, $index1 + 1);
510 next unless (exists ($db->{$hash_in}) and (! defined ($db->{$hash_in})));
512 $index1 = index ($hash_in, ",", 1);
513 my $index2 = index ($hash_in, "\$", 1);
517 if ($index1 < $index2)
523 $param = substr ($hash_in, $index2, 1);
527 # rounds= if available
530 if (substr ($hash_in, $index2, 7) eq "rounds=")
532 my $old_index = $index2;
534 $index2 = index ($hash_in, "\$", $index2 + 1);
538 $iter = substr ($hash_in, $old_index + 7, $index2 - $old_index - 7);
544 my $index3 = rindex ($hash_in, "\$");
548 $salt = substr ($hash_in, $index2, $index3 - $index2);
550 # descrypt (salt in first 2 char)
551 elsif ($mode == 1500)
553 my $index = index ($line, ":");
557 $hash_in = substr ($line, 0, $index);
558 $word = substr ($line, $index + 1);
560 next unless (exists ($db->{$hash_in}) and (! defined ($db->{$hash_in})));
562 $salt = substr ($hash_in, 0, 2);
564 # bcrypt $something$something$salt.hash
565 elsif ($mode == 3200)
567 my $index1 = index ($line, ":", 33);
571 $hash_in = substr ($line, 0, $index1);
572 $word = substr ($line, $index1 + 1);
574 next unless (exists ($db->{$hash_in}) and (! defined ($db->{$hash_in})));
576 my $index2 = index ($hash_in, "\$", 4);
578 $iter = substr ($hash_in, 4, $index2 - 4);
580 my $plain_base64 = substr ($hash_in, $index2 + 1, 22);
585 for (my $i = 0; $i < length ($plain_base64); $i++)
587 my $char = substr ($plain_base64, $i, 1);
588 $encoded .= substr ($base64, index ($itoa64_2, $char), 1);
591 $salt = decode_base64
($encoded);
594 elsif ($mode == 4800)
596 my $index1 = index ($line, ":");
600 my $index2 = index ($line, ":", $index1 + 1);
604 my $index3 = index ($line, ":", $index2 + 1);
608 $salt = substr ($line, $index1 + 1, $index3 - $index1 - 1);
610 $word = substr ($line, $index3 + 1);
612 $hash_in = substr ($line, 0, $index3);
615 elsif ($mode == 5300 || $mode == 5400)
617 my $num_cols = () = $line =~ /:/g;
619 next unless ($num_cols >= 9);
624 for (my $j = 0; $j < 9; $j++)
626 $index1 = index ($line, ":", $index1 + 1);
637 $word = substr ($line, $index1 + 1);
639 $hash_in = substr ($line, 0, $index1);
641 next unless (exists ($db->{$hash_in}) and (! defined ($db->{$hash_in})));
643 my $index2 = rindex ($line, ":", $index1 - 1);
645 $salt = substr ($line, 0, $index2);
648 elsif ($mode == 5500)
650 my $index1 = index ($line, "::");
654 my $index2 = index ($line, ":", $index1 + 2);
658 $index2 = index ($line, ":", $index2 + 1);
662 $salt = substr ($line, 0, $index2);
664 $index2 = index ($line, ":", $index2 + 1);
668 $salt .= substr ($line, $index2 + 1, 16);
670 $index2 = index ($line, ":", $index2 + 1);
674 $hash_in = substr ($line, 0, $index2);
676 next unless (exists ($db->{$hash_in}) and (! defined ($db->{$hash_in})));
678 $word = substr ($line, $index2 + 1);
681 elsif ($mode == 5600)
683 my $index1 = index ($line, "::");
687 my $index2 = index ($line, ":", $index1 + 2);
691 $index2 = index ($line, ":", $index2 + 1);
695 $salt = substr ($line, 0, $index2);
697 $index1 = index ($line, ":", $index2 + 1);
701 $index2 = index ($line, ":", $index1 + 1);
705 $salt .= substr ($line, $index1 + 1, $index2 - $index1 - 1);
707 $hash_in = substr ($line, 0, $index2);
709 # do it later on for this hash mode:
710 # next unless ((exists ($db->{$hash_in}) and (! defined ($db->{$hash_in}))) or (exists ($db->{$mod}) and (! defined ($db->{$mod}))));
712 $word = substr ($line, $index2 + 1);
714 # AIX smd5 something BRACE salt$
715 elsif ($mode == 6300)
717 my $index1 = index ($line, ":");
721 $hash_in = substr ($line, 0, $index1);
722 $word = substr ($line, $index1 + 1);
724 next unless (exists ($db->{$hash_in}) and (! defined ($db->{$hash_in})));
726 my $index2 = index ($hash_in, "}");
727 my $index3 = rindex ($hash_in, "\$");
729 $salt = substr ($hash_in, $index2 + 1, $index3 - $index2 - 1);
731 # AIX: something$salt$ (no $ at position 1)
732 elsif ($mode == 6400 || $mode == 6500 || $mode == 6700)
734 my $index1 = index ($line, ":");
738 $hash_in = substr ($line, 0, $index1);
739 $word = substr ($line, $index1 + 1);
741 next unless (exists ($db->{$hash_in}) and (! defined ($db->{$hash_in})));
743 my $index2 = index ($hash_in, "}");
744 my $index3 = index ($hash_in, "\$");
745 my $index4 = rindex ($hash_in, "\$");
747 $salt = substr ($hash_in, $index3 + 1, $index4 - $index3 - 1);
749 $iter = substr ($hash_in, $index2 + 1, $index3 - $index2 - 1);
751 # 1Password, agilekeychain
752 elsif ($mode == 6600)
754 my $num_cols = () = $line =~ /:/g;
756 next unless ($num_cols > 2);
758 my $index1 = index ($line, ":");
762 $iter = substr ($line, 0, $index1);
764 my $index2 = index ($line, ":", $index1 + 1);
768 $salt = substr ($line, $index1 + 1, $index2 - $index1 - 1);
770 $index1 = index ($line, ":", $index2 + 1);
774 $salt .= substr ($line, $index2 + 1, $index1 - $index2 - 33);
776 $hash_in = substr ($line, 0, $index1);
778 next unless (exists ($db->{$hash_in}) and (! defined ($db->{$hash_in})));
780 $word = substr ($line, $index1 + 1);
782 # 1Password, cloudkeychain
783 elsif ($mode == 8200)
785 my @datas = split (":", $line);
787 next if scalar @datas < 4;
789 my $hash = shift @datas;
790 $salt = shift @datas;
791 $iter = shift @datas;
792 my $data = shift @datas;
794 $hash_in = $hash . ":" . $salt . ":" . $iter . ":" . $data;
798 $word = join (":", @datas);
800 next unless (exists ($db->{$hash_in}) and (! defined ($db->{$hash_in})));
802 # lastpass (hash:iter:salt)
803 elsif ($mode == 6800)
805 my $index1 = index ($line, ":", 34);
809 $hash_in = substr ($line, 0, $index1);
811 # identify lenghts of both salt and plain
813 my $salt_plain = substr ($line, $index1 + 1);
815 my $num_cols = () = $salt_plain =~ /:/g;
824 foreach (my $i = 0; $i < $num_cols; $i++)
826 $index2 = index ($salt_plain, ":", $start);
830 $start = $index2 + 1;
832 $salt = substr ($salt_plain, 0, $index2);
833 $word = substr ($salt_plain, $index2 + 1);
835 # can't be true w/ wrong $hash:$salt, otherwise the
836 # algo must have many collisions
838 if (exists ($db->{$hash_in . ":" . $salt}))
840 $hash_in = $hash_in . ":" . $salt;
846 next unless ($matched); # therefore: true == exists ($db->{$hash_in}
847 next unless (! defined ($db->{$hash_in}));
849 $index1 = index ($hash_in, ":");
850 $index2 = index ($hash_in, ":", $index1 + 1);
852 $iter = substr ($hash_in, $index1 + 1, $index2 - $index1 - 1);
853 $salt = substr ($hash_in, $index2 + 1);
855 # OSX 10.* : $something$iter$salt$
856 elsif ($mode == 7100)
858 my $index1 = index ($line, ":");
862 $hash_in = substr ($line, 0, $index1);
863 $word = substr ($line, $index1 + 1);
865 next unless (exists ($db->{$hash_in}) and (! defined ($db->{$hash_in})));
867 my $index2 = index ($hash_in, "\$", 5);
871 my $index3 = index ($hash_in, "\$", $index2 + 1);
873 $salt = substr ($hash_in, $index2 + 1, $index3 - $index2 - 1);
875 $iter = substr ($hash_in, 4, $index2 - 4);
877 next if (int ($iter) < 1);
879 # grub: something1.something2.something3.iter.salt.
880 elsif ($mode == 7200)
882 my $index1 = index ($line, ":");
886 $hash_in = substr ($line, 0, $index1);
887 $word = substr ($line, $index1 + 1);
889 next unless (exists ($db->{$hash_in}) and (! defined ($db->{$hash_in})));
891 my $index2 = index ($hash_in, ".", 19);
895 my $index3 = index ($hash_in, ".", $index2 + 1);
897 $salt = substr ($hash_in, $index2 + 1, $index3 - $index2 - 1);
899 $iter = substr ($hash_in, 19, $index2 - 19);
901 next if (int ($iter) < 1);
903 # $something1$something2$something3$something4$salt$
904 elsif ($mode == 7500 )
906 my $index1 = index ($line, "\$", 11);
910 my $index2 = index ($line, "\$", $index1 + 1);
914 my $index3 = index ($line, "\$", $index2 + 1);
918 $index2 = index ($line, ":", $index3 + 1);
922 $hash_in = substr ($line, 0, $index2);
923 $word = substr ($line, $index2 + 1);
925 next unless (exists ($db->{$hash_in}) and (! defined ($db->{$hash_in})));
927 $salt = substr ($hash_in, 11, $index3 - 10);
928 $salt .= substr ($hash_in, $index2 - 32) . "\$\$";
929 $salt .= substr ($hash_in, $index3 + 1, $index2 - $index3 - 32 - 1);
932 elsif ($mode == 7700 || $mode == 7800)
934 my $index1 = index ($line, ":");
938 my @split1 = split (":", $line);
940 my @split2 = split ('\$', $split1[0]);
942 next unless scalar @split2 == 2;
944 $hash_in = $split1[0];
946 if (scalar @split1 > 1)
955 next unless (exists ($db->{$hash_in}) and (! defined ($db->{$hash_in})));
960 elsif ($mode == 8300)
962 my @datas = split (":", $line);
964 next if scalar @datas != 5;
969 ($hash, $domain, $salt, $iter, $word) = @datas;
971 $hash_in = $hash . ":" . $domain . ":" . $salt . ":" . $iter;
973 next unless (exists ($db->{$hash_in}) and (! defined ($db->{$hash_in})));
975 $salt = $domain . ":" . $salt;
978 elsif ($mode == 8500)
980 my @line_elements = split (":", $line);
982 next if scalar @line_elements < 2;
986 $hash_in = shift @line_elements;
988 $word = join (":", @line_elements);
992 my @hash_elements = split ('\*', $hash_in);
994 next unless ($hash_elements[0] eq '$racf$');
996 $salt = $hash_elements[1];
998 next unless (exists ($db->{$hash_in}) and (! defined ($db->{$hash_in})));
1001 elsif ($mode == 8700)
1003 # split hash and plain
1004 my $index = index ($line, ":");
1008 $hash_in = substr ($line, 0, $index);
1009 $word = substr ($line, $index + 1);
1011 next unless (exists ($db->{$hash_in}) and (! defined ($db->{$hash_in})));
1013 my $plain_base64 = substr ($hash_in, 2, -1);
1015 ($_, $salt, $param) = domino_decode
($plain_base64);
1018 elsif ($mode == 2612)
1020 next unless (substr ($line, 0, 6) eq '$PHPS$');
1023 my $index1 = index ($line, "\$", 6);
1025 next if $index1 < 1;
1027 $salt = substr ($line, 6, $index1 - 6);
1029 $salt = pack ("H*", $salt);
1031 my $index2 = index ($line, "\:", $index1 + 1);
1033 next if $index2 < 1;
1035 $word = substr ($line, $index2 + 1);
1037 $hash_in = substr ($line, 0, $index2);
1039 next unless (exists ($db->{$hash_in}) and (! defined ($db->{$hash_in})));
1042 elsif ($mode == 3711)
1044 next unless (substr ($line, 0, 3) eq '$B$');
1047 my $index1 = index ($line, "\$", 3);
1049 next if $index1 < 1;
1051 $salt = substr ($line, 3, $index1 - 3);
1053 my $index2 = index ($line, ":", $index1 + 1);
1055 next if $index2 < 1;
1057 $word = substr ($line, $index2 + 1);
1059 $hash_in = substr ($line, 0, $index2);
1061 next unless (exists ($db->{$hash_in}) and (! defined ($db->{$hash_in})));
1064 elsif ($mode == 8900)
1066 next unless (substr ($line, 0, 7) eq 'SCRYPT:');
1069 my $index1 = index ($line, ":", 7);
1071 next if $index1 < 1;
1074 my $N = substr ($line, 7, $index1 - 7);
1076 my $index2 = index ($line, ":", $index1 + 1);
1078 next if $index2 < 1;
1081 my $r = substr ($line, $index1 + 1, $index2 - $index1 - 1);
1083 $index1 = index ($line, ":", $index2 + 1);
1085 next if $index1 < 1;
1088 my $p = substr ($line, $index2 + 1, $index1 - $index2 - 1);
1094 $index2 = index ($line, ":", $index1 + 1);
1096 next if $index2 < 1;
1099 $salt = substr ($line, $index1 + 1, $index2 - $index1 - 1);
1101 $salt = decode_base64
($salt);
1103 $index1 = index ($line, ":", $index2 + 1);
1105 next if $index1 < 1;
1109 $word = substr ($line, $index1 + 1);
1110 $hash_in = substr ($line, 0, $index1);
1112 next unless (exists ($db->{$hash_in}) and (! defined ($db->{$hash_in})));
1115 elsif ($mode == 9100)
1117 # split hash and plain
1118 my $index = index ($line, ":");
1122 $hash_in = substr ($line, 0, $index);
1123 $word = substr ($line, $index + 1);
1125 next unless (exists ($db->{$hash_in}) and (! defined ($db->{$hash_in})));
1127 my $base64_part = substr ($hash_in, 2, -1);
1129 ($_, $salt, $iter, $param) = domino_85x_decode
($base64_part);
1131 next if ($iter < 1);
1133 # Cisco $8$ - PBKDF2-HMAC-SHA256
1134 elsif ($mode == 9200)
1136 next unless (substr ($line, 0, 3) eq '$8$');
1139 my $index1 = index ($line, "\$", 3);
1141 next if $index1 != 17;
1143 my $index2 = index ($line, "\$", $index1 + 1);
1146 $salt = substr ($line, 3, $index1 - 3);
1148 $index1 = index ($line, ":", $index1 + 1);
1150 next if $index1 < 1;
1154 $word = substr ($line, $index1 + 1);
1155 $hash_in = substr ($line, 0, $index1);
1157 next unless (exists ($db->{$hash_in}) and (! defined ($db->{$hash_in})));
1159 # Cisco $9$ - scrypt
1160 elsif ($mode == 9300)
1162 next unless (substr ($line, 0, 3) eq '$9$');
1165 my $index1 = index ($line, "\$", 3);
1167 next if $index1 != 17;
1169 my $index2 = index ($line, "\$", $index1 + 1);
1172 $salt = substr ($line, 3, $index1 - 3);
1174 $index1 = index ($line, ":", $index1 + 1);
1176 next if $index1 < 1;
1180 $word = substr ($line, $index1 + 1);
1181 $hash_in = substr ($line, 0, $index1);
1183 next unless (exists ($db->{$hash_in}) and (! defined ($db->{$hash_in})));
1186 elsif ($mode == 9400)
1188 ($hash_in, $word) = split ":", $line;
1190 next unless defined $hash_in;
1191 next unless defined $word;
1193 my @data = split /\*/, $hash_in;
1195 next unless scalar @data == 8;
1197 next unless (shift @data eq '$office$');
1198 next unless (shift @data eq '2007');
1199 next unless (shift @data eq '20');
1201 my $aes_key_size = shift @data;
1203 next unless (($aes_key_size eq '128') || ($aes_key_size eq '256'));
1204 next unless (shift @data eq '16');
1206 next unless (length $data[0] == 32);
1207 next unless (length $data[1] == 32);
1208 next unless (length $data[2] == 40);
1210 $salt = shift @data;
1211 $param = shift @data;
1212 $param2 = $aes_key_size;
1214 next unless (exists ($db->{$hash_in}) and (! defined ($db->{$hash_in})));
1217 elsif ($mode == 9500)
1219 ($hash_in, $word) = split ":", $line;
1221 next unless defined $hash_in;
1222 next unless defined $word;
1224 my @data = split /\*/, $hash_in;
1226 next unless scalar @data == 8;
1228 next unless (shift @data eq '$office$');
1229 next unless (shift @data eq '2010');
1230 next unless (shift @data eq '100000');
1231 next unless (shift @data eq '128');
1232 next unless (shift @data eq '16');
1234 next unless (length $data[0] == 32);
1235 next unless (length $data[1] == 32);
1236 next unless (length $data[2] == 64);
1238 $salt = shift @data;
1239 $param = shift @data;
1241 next unless (exists ($db->{$hash_in}) and (! defined ($db->{$hash_in})));
1244 elsif ($mode == 9600)
1246 ($hash_in, $word) = split ":", $line;
1248 next unless defined $hash_in;
1249 next unless defined $word;
1251 my @data = split /\*/, $hash_in;
1253 next unless scalar @data == 8;
1255 next unless (shift @data eq '$office$');
1256 next unless (shift @data eq '2013');
1257 next unless (shift @data eq '100000');
1258 next unless (shift @data eq '256');
1259 next unless (shift @data eq '16');
1261 next unless (length $data[0] == 32);
1262 next unless (length $data[1] == 32);
1263 next unless (length $data[2] == 64);
1265 $salt = shift @data;
1266 $param = shift @data;
1268 next unless (exists ($db->{$hash_in}) and (! defined ($db->{$hash_in})));
1271 elsif ($mode == 9700)
1273 ($hash_in, $word) = split ":", $line;
1275 next unless defined $hash_in;
1276 next unless defined $word;
1278 my @data = split /\*/, $hash_in;
1280 next unless scalar @data == 4;
1282 my $signature = shift @data;
1284 next unless (($signature eq '$oldoffice$0') || ($signature eq '$oldoffice$1'));
1286 next unless (length $data[0] == 32);
1287 next unless (length $data[1] == 32);
1288 next unless (length $data[2] == 32);
1290 $salt = shift @data;
1291 $param = shift @data;
1292 $param2 = substr ($signature, 11, 1);
1294 next unless (exists ($db->{$hash_in}) and (! defined ($db->{$hash_in})));
1297 elsif ($mode == 9800)
1299 ($hash_in, $word) = split ":", $line;
1301 next unless defined $hash_in;
1302 next unless defined $word;
1304 my @data = split /\*/, $hash_in;
1306 next unless scalar @data == 4;
1308 my $signature = shift @data;
1310 next unless (($signature eq '$oldoffice$3') || ($signature eq '$oldoffice$4'));
1312 next unless (length $data[0] == 32);
1313 next unless (length $data[1] == 32);
1314 next unless (length $data[2] == 40);
1316 $salt = shift @data;
1317 $param = shift @data;
1318 $param2 = substr ($signature, 11, 1);
1320 next unless (exists ($db->{$hash_in}) and (! defined ($db->{$hash_in})));
1322 # Django (PBKDF2-SHA256)
1323 elsif ($mode == 10000)
1325 next unless (substr ($line, 0, 14) eq 'pbkdf2_sha256$');
1328 my $index1 = index ($line, "\$", 14);
1330 next if $index1 < 1;
1332 my $index2 = index ($line, "\$", $index1 + 1);
1336 $iter = substr ($line, 14, $index1 - 14);
1340 $salt = substr ($line, $index1 + 1, $index2 - $index1 - 1);
1344 $index1 = index ($line, ":", $index2 + 1);
1346 next if $index1 < 1;
1348 $word = substr ($line, $index1 + 1);
1349 $hash_in = substr ($line, 0, $index1);
1351 next unless (exists ($db->{$hash_in}) and (! defined ($db->{$hash_in})));
1354 elsif ($mode == 10100)
1358 ($hash, undef, undef, $salt, $word) = split ":", $line;
1360 next unless defined $hash;
1361 next unless defined $salt;
1362 next unless defined $word;
1364 next unless (length $hash == 16);
1365 next unless (length $salt == 32);
1367 my $hash_in = sprintf ("%s:2:4:%s", $hash, $salt);
1369 next unless (exists ($db->{$hash_in}) and (! defined ($db->{$hash_in})));
1372 elsif ($mode == 10200)
1374 next unless (substr ($line, 0, 10) eq '$cram_md5$');
1377 my $index1 = index ($line, "\$", 10);
1379 next if $index1 < 1;
1383 my $challengeb64 = substr ($line, 10, $index1 - 10);
1384 $salt = decode_base64
($challengeb64);
1388 my $index2 = index ($line, ":", $index1 + 1);
1390 next if $index2 < 1;
1392 my $responseb64 = substr ($line, $index1 + 1, $index2 - $index1 - 1);
1393 my $response = decode_base64
($responseb64);
1395 $param = substr ($response, 0, length ($response) - 32 - 1); # -1 is for space
1397 $word = substr ($line, $index2 + 1);
1398 $hash_in = substr ($line, 0, $index2);
1400 next unless (exists ($db->{$hash_in}) and (! defined ($db->{$hash_in})));
1402 # SAP CODVN H (PWDSALTEDHASH) iSSHA-1
1403 elsif ($mode == 10300)
1405 next unless (substr ($line, 0, 10) eq '{x-issha, ');
1409 my $index1 = index ($line, "}", 10);
1411 next if $index1 < 1;
1413 $iter = substr ($line, 10, $index1 - 10);
1415 $iter = int ($iter);
1419 my $base64_encoded = substr ($line, $index1 + 1);
1420 my $base64_decoded = decode_base64
($base64_encoded);
1422 $salt = substr ($base64_decoded, 20);
1424 my $index2 = index ($line, ":", $index1 + 1);
1426 next if $index2 < 1;
1428 $word = substr ($line, $index2 + 1);
1429 $hash_in = substr ($line, 0, $index2);
1431 next unless (exists ($db->{$hash_in}) and (! defined ($db->{$hash_in})));
1433 # PDF 1.1 - 1.3 (Acrobat 2 - 4)
1434 elsif ($mode == 10400)
1436 ($hash_in, $word) = split ":", $line;
1438 next unless defined $hash_in;
1439 next unless defined $word;
1441 my @data = split /\*/, $hash_in;
1443 next unless scalar @data == 11;
1445 next unless (shift @data eq '$pdf$1');
1446 next unless (shift @data eq '2');
1447 next unless (shift @data eq '40');
1448 my $P = shift @data;
1449 next unless (shift @data eq '0');
1450 next unless (shift @data eq '16');
1451 my $id = shift @data;
1452 next unless (shift @data eq '32');
1453 my $u = shift @data;
1454 next unless (shift @data eq '32');
1455 my $o = shift @data;
1462 next unless (exists ($db->{$hash_in}) and (! defined ($db->{$hash_in})));
1464 # PDF 1.4 - 1.6 (Acrobat 5 - 8)
1465 elsif ($mode == 10500)
1467 ($hash_in, $word) = split ":", $line;
1469 next unless defined $hash_in;
1470 next unless defined $word;
1472 my @data = split /\*/, $hash_in;
1474 next unless scalar @data == 11;
1476 my $V = shift @data; $V = substr ($V, 5, 1);
1477 my $R = shift @data;
1478 next unless (shift @data eq '128');
1479 my $P = shift @data;
1480 my $enc = shift @data;
1481 next unless (shift @data eq '16');
1482 my $id = shift @data;
1483 next unless (shift @data eq '32');
1484 my $u = shift @data;
1485 next unless (shift @data eq '32');
1486 my $o = shift @data;
1496 next unless (exists ($db->{$hash_in}) and (! defined ($db->{$hash_in})));
1498 # PDF 1.7 Level 3 (Acrobat 9)
1499 elsif ($mode == 10600)
1501 ($hash_in, $word) = split ":", $line;
1503 next unless defined $hash_in;
1504 next unless defined $word;
1506 my @data = split /\*/, $hash_in;
1508 next unless scalar @data >= 11;
1510 next unless (shift @data eq '$pdf$5');
1511 next unless (shift @data eq '5');
1512 next unless (shift @data eq '256');
1513 next unless (shift @data eq '-1028');
1514 next unless (shift @data eq '1');
1515 next unless (shift @data eq '16');
1516 my $id = shift @data;
1517 my $rest = join "*", @data;
1522 next unless (exists ($db->{$hash_in}) and (! defined ($db->{$hash_in})));
1524 # PDF 1.7 Level 8 (Acrobat 10 - 11)
1525 elsif ($mode == 10700)
1527 ($hash_in, $word) = split ":", $line;
1529 next unless defined $hash_in;
1530 next unless defined $word;
1532 my @data = split /\*/, $hash_in;
1534 next unless scalar @data >= 11;
1536 next unless (shift @data eq '$pdf$5');
1537 next unless (shift @data eq '6');
1538 next unless (shift @data eq '256');
1539 next unless (shift @data eq '-1028');
1540 next unless (shift @data eq '1');
1541 next unless (shift @data eq '16');
1542 my $id = shift @data;
1543 my $rest = join "*", @data;
1548 next unless (exists ($db->{$hash_in}) and (! defined ($db->{$hash_in})));
1550 # PBKDF2-HMAC-SHA256
1551 elsif ($mode == 10900)
1553 next unless (substr ($line, 0, 7) eq 'sha256:');
1556 my $index1 = index ($line, ":", 7);
1558 next if $index1 < 1;
1560 $iter = substr ($line, 7, $index1 - 7);
1564 my $index2 = index ($line, ":", $index1 + 1);
1566 next if $index2 < 1;
1568 $salt = substr ($line, $index1 + 1, $index2 - $index1 - 1);
1570 $salt = decode_base64
($salt);
1574 $index1 = index ($line, ":", $index2 + 1);
1576 next if $index1 < 1;
1578 # additional param = output len of pbkdf2
1580 my $digest64_encoded = substr ($line, $index2 + 1, $index1 - $index2 - 1);
1582 my $digest = decode_base64
($digest64_encoded);
1584 $param = length ($digest);
1588 $word = substr ($line, $index1 + 1);
1589 $hash_in = substr ($line, 0, $index1);
1591 next unless (exists ($db->{$hash_in}) and (! defined ($db->{$hash_in})));
1593 # PostgreSQL MD5 Authentication
1594 elsif ($mode == 11100)
1596 next unless (substr ($line, 0, 10) eq '$postgres$');
1598 my $index1 = index ($line, "*", 10);
1600 next if $index1 < 1;
1604 $param = substr ($line, 10, $index1 - 10);
1606 # get the 4 byte salt
1608 my $index2 = index ($line, "*", $index1 + 1);
1610 next if $index2 < 1;
1612 $salt = substr ($line, $index1 + 1, $index2 - $index1 - 1);
1616 $index1 = index ($line, ":", $index2 + 1);
1618 next if $index1 < 1;
1620 $word = substr ($line, $index1 + 1);
1621 $hash_in = substr ($line, 0, $index1);
1623 next unless (exists ($db->{$hash_in}) and (! defined ($db->{$hash_in})));
1625 # MySQL MD5 Authentication
1626 elsif ($mode == 11200)
1628 next unless (substr ($line, 0, 9) eq '$mysqlna$');
1630 my $index1 = index ($line, "*", 9);
1632 next if $index1 < 1;
1636 $salt = substr ($line, 9, $index1 - 9);
1640 $index1 = index ($line, ":", $index1 + 1);
1642 next if $index1 < 1;
1644 $word = substr ($line, $index1 + 1);
1645 $hash_in = substr ($line, 0, $index1);
1647 next unless (exists ($db->{$hash_in}) and (! defined ($db->{$hash_in})));
1650 elsif ($mode == 2500)
1652 print "ERROR: verify currently not supported for WPA/WPA2 (because of hashcat's output format)\n";
1656 # Bitcoin/Litecoin wallet.dat
1657 elsif ($mode == 11300)
1659 print "ERROR: verify currently not supported for Bitcoin/Litecoin wallet.dat because of unknown crypt data\n";
1663 # SIP digest authentication (MD5)
1664 elsif ($mode == 11400)
1666 next unless (substr ($line, 0, 6) eq '$sip$*');
1670 my $index1 = index ($line, "*", 6);
1672 next if $index1 < 0;
1674 $param10 = substr ($line, 6, $index1 - 6);
1676 next if (length ($param10) > 32);
1680 my $index2 = index ($line, "*", $index1 + 1);
1682 next if $index2 < 0;
1684 $param11 = substr ($line, $index1 + 1, $index2 - $index1 - 1);
1686 next if (length ($param11) > 32);
1690 $index1 = index ($line, "*", $index2 + 1);
1692 next if $index1 < 0;
1694 $param = substr ($line, $index2 + 1, $index1 - $index2 - 1);
1696 next if (length ($param) > 12);
1700 $index2 = index ($line, "*", $index1 + 1);
1702 next if $index2 < 0;
1704 $param2 = substr ($line, $index1 + 1, $index2 - $index1 - 1);
1706 next if (length ($param2) > 20);
1710 $index1 = index ($line, "*", $index2 + 1);
1712 next if $index1 < 0;
1714 $param6 = substr ($line, $index2 + 1, $index1 - $index2 - 1);
1716 next if (length ($param6) > 24);
1720 $index2 = index ($line, "*", $index1 + 1);
1722 next if $index2 < 0;
1724 $param7 = substr ($line, $index1 + 1, $index2 - $index1 - 1);
1726 next if (length ($param7) > 10);
1730 $index1 = index ($line, "*", $index2 + 1);
1732 next if $index1 < 0;
1734 $param8 = substr ($line, $index2 + 1, $index1 - $index2 - 1);
1736 next if (length ($param8) > 32);
1740 $index2 = index ($line, "*", $index1 + 1);
1742 next if $index2 < 0;
1744 $param9 = substr ($line, $index1 + 1, $index2 - $index1 - 1);
1746 next if (length ($param9) > 32);
1750 $index1 = index ($line, "*", $index2 + 1);
1752 next if $index1 < 0;
1754 $salt = substr ($line, $index2 + 1, $index1 - $index2 - 1);
1756 next if (length ($salt) > 34);
1760 $index2 = index ($line, "*", $index1 + 1);
1762 next if $index2 < 0;
1764 $param4 = substr ($line, $index1 + 1, $index2 - $index1 - 1);
1766 next if (length ($param4) > 12);
1770 $index1 = index ($line, "*", $index2 + 1);
1772 next if $index1 < 0;
1774 $param3 = substr ($line, $index2 + 1, $index1 - $index2 - 1);
1776 next if (length ($param3) > 10);
1780 $index2 = index ($line, "*", $index1 + 1);
1782 next if $index2 < 0;
1784 $param5 = substr ($line, $index1 + 1, $index2 - $index1 - 1);
1786 next if (length ($param5) > 8);
1790 $index1 = index ($line, "*", $index2 + 1);
1792 next if $index1 < 0;
1794 my $directive = substr ($line, $index2 + 1, $index1 - $index2 - 1);
1796 next unless ($directive eq "MD5");
1800 $index2 = index ($line, ":", $index1 + 1);
1802 next if $index2 < 0;
1804 my $hex_digest = substr ($line, $index1 + 1, $index2 - $index1 - 1);
1806 next unless (length ($hex_digest) == 32);
1808 $word = substr ($line, $index2 + 1);
1809 $hash_in = substr ($line, 0, $index2);
1811 next unless (exists ($db->{$hash_in}) and (! defined ($db->{$hash_in})));
1814 elsif ($mode == 11600)
1816 next unless (substr ($line, 0, 4) eq '$7z$');
1820 my $index1 = index ($line, '$', 4);
1822 next if $index1 < 0;
1824 my $p = substr ($line, 4, $index1 - 4);
1826 next unless ($p eq "0");
1830 my $index2 = index ($line, '$', $index1 + 1);
1832 next if $index2 < 0;
1834 $iter = substr ($line, $index1 + 1, $index2 - $index1 - 1);
1836 # seven zip salt length
1838 $index1 = index ($line, '$', $index2 + 1);
1840 next if $index1 < 0;
1842 $param = substr ($line, $index2 + 1, $index1 - $index2 - 1);
1846 $index2 = index ($line, '$', $index1 + 1);
1848 next if $index2 < 0;
1850 $param2 = substr ($line, $index1 + 1, $index2 - $index1 - 1);
1854 $index1 = index ($line, '$', $index2 + 1);
1856 next if $index1 < 0;
1858 $param3 = substr ($line, $index2 + 1, $index1 - $index2 - 1);
1862 $index2 = index ($line, '$', $index1 + 1);
1864 next if $index2 < 0;
1866 $salt = substr ($line, $index1 + 1, $index2 - $index1 - 1);
1868 $salt = pack ("H*", $salt);
1872 $index1 = index ($line, '$', $index2 + 1);
1874 next if $index1 < 0;
1876 my $crc = substr ($line, $index2 + 1, $index1 - $index2 - 1);
1878 # ignore this crc, we don't need to pass it to gen_hash ()
1882 $index2 = index ($line, '$', $index1 + 1);
1884 next if $index2 < 0;
1886 $param4 = substr ($line, $index1 + 1, $index2 - $index1 - 1);
1890 $index1 = index ($line, '$', $index2 + 1);
1892 next if $index1 < 0;
1894 $param5 = substr ($line, $index2 + 1, $index1 - $index2 - 1);
1898 $index2 = index ($line, ':', $index1 + 1);
1900 next if $index2 < 0;
1902 $param6 = substr ($line, $index1 + 1, $index2 - $index1 - 1);
1903 $param6 = pack ("H*", $param6);
1905 $word = substr ($line, $index2 + 1);
1906 $hash_in = substr ($line, 0, $index2);
1908 next unless (exists ($db->{$hash_in}) and (! defined ($db->{$hash_in})));
1911 elsif ($mode == 11900)
1913 next unless (substr ($line, 0, 4) eq 'md5:');
1916 my $index1 = index ($line, ":", 4);
1918 next if $index1 < 1;
1920 $iter = substr ($line, 4, $index1 - 4);
1924 my $index2 = index ($line, ":", $index1 + 1);
1926 next if $index2 < 1;
1928 $salt = substr ($line, $index1 + 1, $index2 - $index1 - 1);
1930 $salt = decode_base64
($salt);
1934 $index1 = index ($line, ":", $index2 + 1);
1936 next if $index1 < 1;
1938 # additional param = output len of pbkdf2
1940 my $digest64_encoded = substr ($line, $index2 + 1, $index1 - $index2 - 1);
1942 my $digest = decode_base64
($digest64_encoded);
1944 $param = length ($digest);
1948 $word = substr ($line, $index1 + 1);
1949 $hash_in = substr ($line, 0, $index1);
1951 next unless (exists ($db->{$hash_in}) and (! defined ($db->{$hash_in})));
1954 elsif ($mode == 12000)
1956 next unless (substr ($line, 0, 5) eq 'sha1:');
1959 my $index1 = index ($line, ":", 5);
1961 next if $index1 < 1;
1963 $iter = substr ($line, 5, $index1 - 5);
1967 my $index2 = index ($line, ":", $index1 + 1);
1969 next if $index2 < 1;
1971 $salt = substr ($line, $index1 + 1, $index2 - $index1 - 1);
1973 $salt = decode_base64
($salt);
1977 $index1 = index ($line, ":", $index2 + 1);
1979 next if $index1 < 1;
1981 # additional param = output len of pbkdf2
1983 my $digest64_encoded = substr ($line, $index2 + 1, $index1 - $index2 - 1);
1985 my $digest = decode_base64
($digest64_encoded);
1987 $param = length ($digest);
1991 $word = substr ($line, $index1 + 1);
1992 $hash_in = substr ($line, 0, $index1);
1994 next unless (exists ($db->{$hash_in}) and (! defined ($db->{$hash_in})));
1996 # PBKDF2-HMAC-SHA512
1997 elsif ($mode == 12100)
1999 next unless (substr ($line, 0, 7) eq 'sha512:');
2002 my $index1 = index ($line, ":", 7);
2004 next if $index1 < 1;
2006 $iter = substr ($line, 7, $index1 - 7);
2010 my $index2 = index ($line, ":", $index1 + 1);
2012 next if $index2 < 1;
2014 $salt = substr ($line, $index1 + 1, $index2 - $index1 - 1);
2016 $salt = decode_base64
($salt);
2020 $index1 = index ($line, ":", $index2 + 1);
2022 next if $index1 < 1;
2024 # additional param = output len of pbkdf2
2026 my $digest64_encoded = substr ($line, $index2 + 1, $index1 - $index2 - 1);
2028 my $digest = decode_base64
($digest64_encoded);
2030 $param = length ($digest);
2034 $word = substr ($line, $index1 + 1);
2035 $hash_in = substr ($line, 0, $index1);
2037 next unless (exists ($db->{$hash_in}) and (! defined ($db->{$hash_in})));
2040 elsif ($mode == 12200)
2042 next unless (substr ($line, 0, 12) eq '$ecryptfs$0$');
2044 # check if default salt
2048 $param = 0 if (substr ($line, 12, 2) eq '1$');
2056 if ($param == 0) # we need to extract the salt
2058 $index1 = index ($line, '$', $index1);
2060 next if $index1 < 1;
2062 my $index2 = index ($line, '$', $index1 + 1);
2064 next if $index2 < 1;
2066 $salt = substr ($line, $index1 + 1, $index2 - $index1 - 1);
2071 $index1 = index ($line, ':', $index1 + 1);
2073 next if $index1 < 1;
2077 $word = substr ($line, $index1 + 1);
2078 $hash_in = substr ($line, 0, $index1);
2080 next unless (exists ($db->{$hash_in}) and (! defined ($db->{$hash_in})));
2082 # Oracle T: Type (Oracle 12+)
2083 elsif ($mode == 12300)
2085 my $index1 = index ($line, ':');
2087 next if ($index1 != 160);
2091 $salt = substr ($line, 128, 32);
2095 $word = substr ($line, $index1 + 1);
2096 $hash_in = substr ($line, 0, $index1);
2098 next unless (exists ($db->{$hash_in}) and (! defined ($db->{$hash_in})));
2100 # BSDiCrypt, Extended DES
2101 elsif ($mode == 12400)
2103 next unless (substr ($line, 0, 1) eq '_');
2105 my $index1 = index ($line, ':', 20);
2107 next if ($index1 != 20);
2111 $iter = substr ($line, 1, 4);
2113 $iter = base64_to_int24
($iter);
2117 $salt = substr ($line, 5, 4);
2121 $word = substr ($line, $index1 + 1);
2122 $hash_in = substr ($line, 0, $index1);
2124 next unless (exists ($db->{$hash_in}) and (! defined ($db->{$hash_in})));
2126 # Blockchain, My Wallet
2127 elsif ($mode == 12700)
2129 my $index1 = index ($line, ':');
2131 next if ($index1 < 0);
2133 $hash_in = substr ($line, 0, $index1);
2134 $word = substr ($line, $index1 + 1);
2136 my (undef, $signature, $data_len, $data_buf) = split '\$', $hash_in;
2138 next unless ($signature eq "blockchain");
2140 next unless (($data_len * 2) == length $data_buf);
2142 $salt = substr ($data_buf, 0, 32);
2143 $param = substr ($data_buf, 32);
2145 next unless (exists ($db->{$hash_in}) and (! defined ($db->{$hash_in})));
2147 elsif ($mode == 12800)
2149 ($hash_in, $word) = split ":", $line;
2151 next unless defined $hash_in;
2152 next unless defined $word;
2154 my @data = split /\,/, $hash_in;
2156 next unless scalar @data == 4;
2158 next unless (shift @data eq 'v1;PPH1_MD4');
2160 $salt = shift @data;
2161 $iter = shift @data;
2163 next unless (exists ($db->{$hash_in}) and (! defined ($db->{$hash_in})));
2165 elsif ($mode == 12900)
2167 ($hash_in, $word) = split ":", $line;
2169 next unless defined $hash_in;
2170 next unless defined $word;
2172 next unless length $hash_in == 160;
2174 $param = substr ($hash_in, 0, 64);
2175 $salt = substr ($hash_in, 128, 32);
2178 next unless (exists ($db->{$hash_in}) and (! defined ($db->{$hash_in})));
2180 elsif ($mode == 13000)
2184 ($hash_line, $word) = split ":", $line;
2186 next unless defined $hash_line;
2187 next unless defined $word;
2189 my @data = split ('\$', $hash_line);
2191 next unless scalar @data == 8;
2195 my $signature = shift @data;
2196 my $salt_len = shift @data;
2197 my $salt_buf = shift @data;
2198 my $iterations = shift @data;
2199 my $iv = shift @data;
2200 my $pswcheck_len = shift @data;
2201 my $pswcheck = shift @data;
2203 next unless ($signature eq "rar5");
2204 next unless ($salt_len == 16);
2205 next unless ($pswcheck_len == 8);
2208 $iter = $iterations;
2209 $hash_in = $pswcheck;
2212 next unless (exists ($db->{$hash_line}) and (! defined ($db->{$hash_line})));
2214 elsif ($mode == 13100)
2216 ($hash_in, $word) = split ":", $line;
2218 next unless defined $hash_in;
2219 next unless defined $word;
2221 my @data = split ('\$', $hash_in);
2223 next unless scalar @data == 8;
2227 my $signature = shift @data;
2228 my $algorithm = shift @data;
2229 my $user = shift @data;
2230 $user = substr ($user, 1);
2231 my $realm = shift @data;
2232 my $spn = shift @data;
2233 $spn = substr ($spn, 0, length ($spn) - 1);
2234 my $checksum = shift @data;
2235 my $edata2 = shift @data;
2237 next unless ($signature eq "krb5tgs");
2238 next unless (length ($checksum) == 32);
2239 next unless (length ($edata2) >= 64);
2241 $salt = $user . '$' . $realm . '$' . $spn . '$';
2246 next unless (exists ($db->{$hash_in}) and (! defined ($db->{$hash_in})));
2248 elsif ($mode == 13200)
2250 ($hash_in, $word) = split ":", $line;
2252 next unless defined $hash_in;
2253 next unless defined $word;
2255 my @data = split ('\*', $hash_in);
2257 next unless scalar @data == 5;
2259 my $signature = shift @data;
2260 my $version = shift @data;
2261 my $iteration = shift @data;
2262 my $mysalt = shift @data;
2263 my $digest = shift @data;
2265 next unless ($signature eq '$axcrypt$');
2266 next unless (length ($mysalt) == 32);
2267 next unless (length ($digest) == 48);
2269 $salt = $iteration . '*' . $mysalt;
2272 next unless (exists ($db->{$hash_in}) and (! defined ($db->{$hash_in})));
2274 elsif ($mode == 13300)
2276 ($hash_in, $word) = split ":", $line;
2278 next unless defined $hash_in;
2279 next unless defined $word;
2281 my @data = split ('\$', $hash_in);
2283 next unless scalar @data == 2;
2287 my $signature = shift @data;
2288 my $digest = shift @data;
2290 next unless ($signature eq '$axcrypt_sha1');
2291 next unless (length ($digest) == 32 || length ($digest) == 40);
2293 next unless (exists ($db->{$hash_in}) and (! defined ($db->{$hash_in})));
2295 elsif ($mode == 13400)
2297 ($hash_in, $word) = split ":", $line;
2299 next unless defined $hash_in;
2300 next unless defined $word;
2302 my @data = split ('\*', $hash_in);
2304 next unless (scalar @data == 9
2305 || scalar @data == 11
2306 || scalar @data == 12
2307 || scalar @data == 14);
2309 my $signature = shift @data;
2310 next unless ($signature eq '$keepass$');
2312 my $version = shift @data;
2313 next unless ($version == 1 || $version == 2);
2315 my $iteration = shift @data;
2317 my $algorithm = shift @data;
2319 my $final_random_seed = shift @data;
2323 next unless (length ($final_random_seed) == 32);
2325 elsif ($version == 2)
2327 next unless (length ($final_random_seed) == 64);
2330 my $transf_random_seed = shift @data;
2331 next unless (length ($transf_random_seed) == 64);
2333 my $enc_iv = shift @data;
2334 next unless (length ($enc_iv) == 32);
2338 my $contents_hash = shift @data;
2339 next unless (length ($contents_hash) == 64);
2341 my $inline_flags = shift @data;
2342 next unless ($inline_flags == 1);
2344 my $contents_len = shift @data;
2346 my $contents = shift @data;
2347 next unless (length ($contents) == $contents_len * 2);
2349 elsif ($version == 2)
2351 my $expected_bytes = shift @data;
2352 next unless (length ($expected_bytes) == 64);
2354 my $contents_hash = shift @data;
2355 next unless (length ($contents_hash) == 64);
2358 if (scalar @data == 12 || scalar @data == 14)
2360 my $inline_flags = shift @data;
2361 next unless ($inline_flags == 1);
2363 my $keyfile_len = shift @data;
2364 next unless ($keyfile_len == 64);
2366 my $keyfile = shift @data;
2367 next unless (length ($keyfile) == $keyfile_len);
2370 $salt = substr ($hash_in, length ("*keepass*") + 1);
2371 $param = 1; # distinguish between encrypting vs decrypting
2373 next unless (exists ($db->{$hash_in}) and (! defined ($db->{$hash_in})));
2375 elsif ($mode == 13600)
2377 ($hash_in, $word) = split ":", $line;
2379 next unless defined $hash_in;
2380 next unless defined $word;
2382 my @data = split ('\*', $hash_in);
2384 next unless scalar @data == 10;
2386 my $tag_start = shift @data;
2387 my $type = shift @data;
2388 my $mode = shift @data;
2389 my $magic = shift @data;
2390 my $salt = shift @data;
2391 my $verify_bytes = shift @data;
2392 my $length = shift @data;
2393 my $data = shift @data;
2394 my $auth = shift @data;
2395 my $tag_end = shift @data;
2397 next unless ($tag_start eq '$zip2$');
2398 next unless ($tag_end eq '$/zip2$');
2407 next unless (exists ($db->{$hash_in}) and (! defined ($db->{$hash_in})));
2411 print "ERROR: hash mode is not supported\n";
2416 if ($word =~ m/^\$HEX\[[0-9a-fA-F]*\]$/)
2418 $word = pack ("H*", substr ($word, 5, -1));
2421 # finally generate the hash
2426 # check both variations
2427 $hash_out = gen_hash
($mode, $word, $salt, $iter, 1);
2429 $len = length $hash_out; # == length $alternative
2431 if (substr ($line, 0, $len) ne $hash_out)
2433 my $alternative = gen_hash
($mode, $word, $salt, $iter, 2);
2435 return unless (substr ($line, 0, $len) eq $alternative);
2438 elsif ($mode == 8700)
2440 $hash_out = gen_hash
($mode, $word, $salt, 0, $param);
2442 $len = length $hash_out;
2444 return unless (substr ($line, 0, $len) eq $hash_out);
2446 elsif ($mode == 8900)
2448 $hash_out = gen_hash
($mode, $word, $salt, 0, $param, $param2, $param3);
2450 $len = length $hash_out;
2452 return unless (substr ($line, 0, $len) eq $hash_out);
2454 elsif ($mode == 9100)
2456 $hash_out = gen_hash
($mode, $word, $salt, $iter, $param);
2458 $len = length $hash_out;
2460 return unless (substr ($line, 0, $len) eq $hash_out);
2462 elsif ($mode == 3300)
2464 $hash_out = gen_hash
($mode, $word, $salt, $iter, $param);
2466 $len = length $hash_out;
2468 return unless (substr ($line, 0, $len) eq $hash_out);
2470 elsif ($mode == 5100)
2472 # check 3 variants (start, middle, end)
2476 $hash_out = gen_hash
($mode, $word, $salt, $iter, $idx++);
2478 $len = length $hash_out; # == length $alternative
2480 if (substr ($line, 0, $len) ne $hash_out)
2482 my $alternative = gen_hash
($mode, $word, $salt, $iter, $idx++);
2484 if (substr ($line, 0, $len) ne $alternative)
2486 my $alternative = gen_hash
($mode, $word, $salt, $iter, $idx++);
2488 return unless (substr ($line, 0, $len) eq $alternative);
2492 elsif ($mode == 9400)
2494 $hash_out = gen_hash
($mode, $word, $salt, 50000, $param, $param2);
2496 $len = length $hash_out;
2498 return unless (substr ($line, 0, $len) eq $hash_out);
2500 elsif ($mode == 9500)
2502 $hash_out = gen_hash
($mode, $word, $salt, 100000, $param);
2504 $len = length $hash_out;
2506 return unless (substr ($line, 0, $len) eq $hash_out);
2508 elsif ($mode == 9600)
2510 $hash_out = gen_hash
($mode, $word, $salt, 100000, $param);
2512 $len = length $hash_out;
2514 return unless (substr ($line, 0, $len) eq $hash_out);
2516 elsif ($mode == 9700)
2518 $hash_out = gen_hash
($mode, $word, $salt, 0, $param, $param2);
2520 $len = length $hash_out;
2522 return unless (substr ($line, 0, $len) eq $hash_out);
2524 elsif ($mode == 9800)
2526 $hash_out = gen_hash
($mode, $word, $salt, 0, $param, $param2);
2528 $len = length $hash_out;
2530 return unless (substr ($line, 0, $len) eq $hash_out);
2532 elsif ($mode == 10400)
2534 $hash_out = gen_hash
($mode, $word, $salt, 0, $param, $param2, $param3);
2536 $len = length $hash_out;
2538 return unless (substr ($line, 0, $len) eq $hash_out);
2540 elsif ($mode == 10500)
2542 $hash_out = gen_hash
($mode, $word, $salt, 0, $param, $param2, $param3, $param4, $param5, $param6);
2544 $len = length $hash_out;
2546 return unless (substr ($line, 0, $len) eq $hash_out);
2548 elsif ($mode == 10600)
2550 $hash_out = gen_hash
($mode, $word, $salt, 0, $param);
2552 $len = length $hash_out;
2554 return unless (substr ($line, 0, $len) eq $hash_out);
2556 elsif ($mode == 10700)
2558 $hash_out = gen_hash
($mode, $word, $salt, 0, $param);
2560 $len = length $hash_out;
2562 return unless (substr ($line, 0, $len) eq $hash_out);
2564 elsif ($mode == 10900)
2566 $hash_out = gen_hash
($mode, $word, $salt, $iter, $param);
2568 $len = length $hash_out;
2570 return unless (substr ($line, 0, $len) eq $hash_out);
2572 elsif ($mode == 11100)
2574 $hash_out = gen_hash
($mode, $word, $salt, $iter, $param);
2576 $len = length $hash_out;
2578 return unless (substr ($line, 0, $len) eq $hash_out);
2580 elsif ($mode == 11400)
2582 $hash_out = gen_hash
($mode, $word, $salt, $iter, $param, $param2, $param3, $param4, $param5, $param6, $param7, $param8, $param9, $param10, $param11);
2584 $len = length $hash_out;
2586 return unless (substr ($line, 0, $len) eq $hash_out);
2588 elsif ($mode == 11600)
2590 $hash_out = gen_hash
($mode, $word, $salt, $iter, $param, $param2, $param3, $param4, $param5, $param6);
2592 $len = length $hash_out;
2594 return unless (substr ($line, 0, $len) eq $hash_out);
2596 elsif ($mode == 11900)
2598 $hash_out = gen_hash
($mode, $word, $salt, $iter, $param);
2600 $len = length $hash_out;
2602 return unless (substr ($line, 0, $len) eq $hash_out);
2604 elsif ($mode == 12000)
2606 $hash_out = gen_hash
($mode, $word, $salt, $iter, $param);
2608 $len = length $hash_out;
2610 return unless (substr ($line, 0, $len) eq $hash_out);
2612 elsif ($mode == 12100)
2614 $hash_out = gen_hash
($mode, $word, $salt, $iter, $param);
2616 $len = length $hash_out;
2618 return unless (substr ($line, 0, $len) eq $hash_out);
2620 elsif ($mode == 12200)
2622 $hash_out = gen_hash
($mode, $word, $salt, $iter, $param);
2624 $len = length $hash_out;
2626 return unless (substr ($line, 0, $len) eq $hash_out);
2628 elsif ($mode == 12700)
2630 # this is very special, we can't call gen_hash () because the param part is not always the same
2631 # we only know that it should contain the letters "guid" at the beginning of the decryted string
2633 my $pbkdf2 = Crypt
::PBKDF2
->new (
2634 hash_class
=> 'HMACSHA1',
2639 my $salt_bin = pack ("H*", $salt);
2641 my $key = $pbkdf2->PBKDF2 ($salt_bin, $word);
2643 my $cipher = Crypt
::CBC
->new ({
2645 cipher
=> "Crypt::Rijndael",
2652 my $param_bin = pack ("H*", $param);
2654 my $decrypted = $cipher->decrypt ($param_bin);
2656 my $decrypted_part = substr ($decrypted, 1, 16);
2658 return unless ($decrypted_part =~ /"guid"/);
2660 $hash_out = $hash_in;
2662 elsif ($mode == 12900)
2664 $hash_out = gen_hash
($mode, $word, $salt, $iter, $param);
2666 $len = length $hash_out;
2668 return unless (substr ($line, 0, $len) eq $hash_out);
2670 elsif ($mode == 13000)
2672 $hash_out = gen_hash
($mode, $word, $salt, $iter, $param);
2674 $len = length $hash_out;
2676 return unless (substr ($line, 0, $len) eq $hash_out);
2678 elsif ($mode == 13100)
2680 $hash_out = gen_hash
($mode, $word, $salt, $iter, $param, $param2);
2682 $len = length $hash_out;
2684 return unless (substr ($line, 0, $len) eq $hash_out);
2686 elsif ($mode == 13200)
2688 $hash_out = gen_hash
($mode, $word, $salt, $iter, $param);
2690 $len = length $hash_out;
2692 return unless (substr ($line, 0, $len) eq $hash_out);
2694 elsif ($mode == 13400)
2696 $hash_out = gen_hash
($mode, $word, $salt, $iter, $param);
2698 $len = length $hash_out;
2700 return unless (substr ($line, 0, $len) eq $hash_out);
2702 elsif ($mode == 13600)
2704 $hash_out = gen_hash
($mode, $word, undef, undef, $param, $param2, $param3, $param4, $param5, $param6);
2706 $len = length $hash_out;
2708 return unless (substr ($line, 0, $len) eq $hash_out);
2712 $hash_out = gen_hash
($mode, $word, $salt, $iter);
2714 $len = length $hash_out;
2719 # allow $P$ and $H$ for -m 400
2720 next unless (substr ($line, 3, $len - 3) eq substr ($hash_out, 3));
2722 elsif ($mode == 5600)
2724 # hashcat outputs the user name always upper-case, we need
2725 next unless (substr ($line, 0, $len) eq $hash_out);
2729 my $hash_out_lower = lc ($hash_out);
2731 for my $key (keys %{$db})
2733 if (lc ($key) eq $hash_out_lower)
2745 next unless (substr ($line, 0, $len) eq $hash_out);
2749 # do not forget "exists ($db->$hash_out)" should be done above!
2750 $db->{$hash_out} = $word;
2751 print OUT
$line . "\n";
2760 my $mode = shift || 0;
2762 while (my $word_buf = <>)
2766 next if length ($word_buf) > 31;
2774 for (my $i = 0; $i < 256; $i++)
2776 my $c = get_random_chr
(0x30, 0x39);
2778 push (@salt_arr, $c);
2781 my $salt_buf = join ("", @salt_arr);
2789 if ($mode == 0 || $mode == 100 || $mode == 101 || $mode == 133 || $mode == 200 || $mode == 300 || $mode == 600 || $mode == 900 || $mode == 1000 || $mode == 1400 || $mode == 1700 || $mode == 2400 || $mode == 2600 || $mode == 3500 || $mode == 4300 || $mode == 4400 || $mode == 4500 || $mode == 4600 || $mode == 4700 || $mode == 5000 || $mode == 5100 || $mode == 6000 || $mode == 6100 || $mode == 6900 || $mode == 5700 || $mode == 9900 || $mode == 10800 || $mode == 11500 || $mode == 13300)
2791 $tmp_hash = gen_hash
($mode, $word_buf, "");
2793 elsif ($mode == 10 || $mode == 20 || $mode == 23 || $mode == 30 || $mode == 40 || $mode == 50 || $mode == 60 || $mode == 110 || $mode == 120 || $mode == 130 || $mode == 140 || $mode == 150 || $mode == 160 || $mode == 1410 || $mode == 1420 || $mode == 1430 || $mode == 1440 || $mode == 1450 || $mode == 1460 || $mode == 1710 || $mode == 1711 || $mode == 1720 || $mode == 1730 || $mode == 1740 || $mode == 1750 || $mode == 1760 || $mode == 3610 || $mode == 3710 || $mode == 3711 || $mode == 3720 || $mode == 3800 || $mode == 3910 || $mode == 4010 || $mode == 4110 || $mode == 4210 || $mode == 4900 || $mode == 8900 || $mode == 10000 || $mode == 10200 || $mode == 10900 || $mode == 11900 || $mode == 12000 || $mode == 12100)
2795 my $salt_len = get_random_num
(1, 15);
2797 $tmp_hash = gen_hash
($mode, $word_buf, substr ($salt_buf, 0, $salt_len));
2799 elsif ($mode == 11 || $mode == 12 || $mode == 7600 || $mode == 12300)
2801 $tmp_hash = gen_hash
($mode, $word_buf, substr ($salt_buf, 0, 32));
2805 $tmp_hash = gen_hash
($mode, $word_buf, substr ($salt_buf, 0, 2));
2809 my $salt_len = get_random_num
(1, 11);
2811 $tmp_hash = gen_hash
($mode, $word_buf, substr ($salt_buf, 0, $salt_len));
2813 elsif ($mode == 111 || $mode == 122 || $mode == 131 || $mode == 132 || $mode == 400 || $mode == 500 || $mode == 1600 || $mode == 1722 || $mode == 1731 || $mode == 1800 || $mode == 6300 || $mode == 7900 || $mode == 8100 || $mode == 11100)
2815 $tmp_hash = gen_hash
($mode, $word_buf, substr ($salt_buf, 0, 8));
2817 elsif ($mode == 112)
2819 $tmp_hash = gen_hash
($mode, $word_buf, substr ($salt_buf, 0, 20));
2821 elsif ($mode == 121)
2823 my $salt_len = get_random_num
(1, 9);
2825 $tmp_hash = gen_hash
($mode, $word_buf, substr ($salt_buf, 0, $salt_len));
2827 elsif ($mode == 125)
2829 $tmp_hash = gen_hash
($mode, $word_buf, substr ($salt_buf, 0, 8));
2831 elsif ($mode == 141 || $mode == 1441)
2833 my $salt_len = get_random_num
(1, 15);
2835 $tmp_hash = gen_hash
($mode, $word_buf, substr ($salt_buf, 0, $salt_len));
2837 elsif ($mode == 1100)
2839 my $salt_len = get_random_num
(1, 19);
2841 $tmp_hash = gen_hash
($mode, $word_buf, substr ($salt_buf, 0, $salt_len));
2843 elsif ($mode == 1500)
2845 next if length ($word_buf) > 8;
2847 $tmp_hash = gen_hash
($mode, $word_buf, substr ($salt_buf, 0, 2));
2849 elsif ($mode == 2100)
2851 next if length ($word_buf) > 13;
2853 my $salt_len = get_random_num
(1, 19);
2855 $tmp_hash = gen_hash
($mode, $word_buf, substr ($salt_buf, 0, $salt_len));
2857 elsif ($mode == 2410)
2859 next if length ($word_buf) > 15;
2861 my $salt_len = get_random_num
(1, 15);
2863 my $word_len = length ($word_buf);
2865 $salt_len = min
($salt_len, 15 - $word_len);
2867 $tmp_hash = gen_hash
($mode, $word_buf, substr ($salt_buf, 0, $salt_len));
2869 elsif ($mode == 2500)
2871 next if length ($word_buf) < 8;
2873 my $salt_len = get_random_num
(0, 32);
2875 $tmp_hash = gen_hash
($mode, $word_buf, substr ($salt_buf, 0, $salt_len));
2877 elsif ($mode == 2611)
2879 $tmp_hash = gen_hash
($mode, $word_buf, substr ($salt_buf, 0, 3));
2881 elsif ($mode == 2612)
2883 my $salt_len = get_random_num
(1, 22);
2885 $tmp_hash = gen_hash
($mode, $word_buf, substr ($salt_buf, 0, $salt_len));
2887 elsif ($mode == 2711)
2889 $tmp_hash = gen_hash
($mode, $word_buf, substr ($salt_buf, 0, 30));
2891 elsif ($mode == 2811)
2893 $tmp_hash = gen_hash
($mode, $word_buf, substr ($salt_buf, 0, 5));
2895 elsif ($mode == 3000)
2897 next if length ($word_buf) > 7;
2899 $tmp_hash = gen_hash
($mode, $word_buf, "");
2901 elsif ($mode == 3100)
2903 $tmp_hash = gen_hash
($mode, $word_buf, substr ($salt_buf, 0, 10));
2905 elsif ($mode == 3200 || $mode == 5800 || $mode == 6400 || $mode == 6500 || $mode == 6700 || $mode == 7400 || $mode == 3300 || $mode == 8000 || $mode == 9100 || $mode == 12200)
2907 $tmp_hash = gen_hash
($mode, $word_buf, substr ($salt_buf, 0, 16));
2909 elsif ($mode == 3800 || $mode == 4900)
2911 my $salt_len = get_random_num
(1, 11);
2913 $tmp_hash = gen_hash
($mode, $word_buf, substr ($salt_buf, 0, $salt_len));
2915 elsif ($mode == 4800)
2917 $salt_buf = get_random_md5chap_salt
(substr ($salt_buf, 0, 16));
2919 $tmp_hash = gen_hash
($mode, $word_buf, $salt_buf);
2921 elsif ($mode == 5300 || $mode == 5400)
2923 $salt_buf = get_random_ike_salt
();
2925 $tmp_hash = gen_hash
($mode, $word_buf, $salt_buf);
2927 elsif ($mode == 5500)
2929 my $user_len = get_random_num
(0, 15);
2930 my $domain_len = get_random_num
(0, 15);
2932 $salt_buf = get_random_netntlmv1_salt
($user_len, $domain_len);
2934 $tmp_hash = gen_hash
($mode, $word_buf, $salt_buf);
2936 elsif ($mode == 5600)
2938 my $user_len = get_random_num
(0, 15);
2939 my $domain_len = get_random_num
(0, 15);
2941 $salt_buf = get_random_netntlmv2_salt
($user_len, $domain_len);
2943 $tmp_hash = gen_hash
($mode, $word_buf, $salt_buf);
2945 elsif ($mode == 6600)
2947 $salt_buf = get_random_agilekeychain_salt
();
2949 $tmp_hash = gen_hash
($mode, $word_buf, $salt_buf);
2951 elsif ($mode == 6800)
2953 my $email_len = get_random_num
(1, 15);
2957 for (my $i = 0; $i < $email_len; $i++)
2959 $email .= get_random_chr
(0x61, 0x7a);
2962 $email .= '@trash-mail.com';
2964 $tmp_hash = gen_hash
($mode, $word_buf, $email);
2966 elsif ($mode == 7100)
2968 $tmp_hash = gen_hash
($mode, $word_buf, substr ($salt_buf, 0, 64));
2970 elsif ($mode == 7200)
2972 $tmp_hash = gen_hash
($mode, $word_buf, substr ($salt_buf, 0, 128));
2974 elsif ($mode == 7300)
2976 my $salt_len = get_random_num
(32, 256);
2978 $tmp_hash = gen_hash
($mode, $word_buf, substr ($salt_buf, 0, $salt_len));
2980 elsif ($mode == 7500)
2982 $salt_buf = get_random_kerberos5_salt
(substr ($salt_buf, 0, 16));
2984 $tmp_hash = gen_hash
($mode, $word_buf, $salt_buf);
2986 elsif ($mode == 7700)
2988 next if length ($word_buf) > 8;
2990 $tmp_hash = gen_hash
($mode, $word_buf, substr ($salt_buf, 0, 12));
2992 elsif ($mode == 7800)
2994 $tmp_hash = gen_hash
($mode, $word_buf, substr ($salt_buf, 0, 12));
2996 elsif ($mode == 8200)
2998 $salt_buf = get_random_cloudkeychain_salt
();
3000 $tmp_hash = gen_hash
($mode, $word_buf, $salt_buf);
3002 elsif ($mode == 8300)
3004 $salt_buf = get_random_dnssec_salt
();
3006 $tmp_hash = gen_hash
($mode, $word_buf, $salt_buf);
3008 elsif ($mode == 8400 || $mode == 11200)
3010 $tmp_hash = gen_hash
($mode, $word_buf, substr ($salt_buf, 0, 40));
3012 elsif ($mode == 8500)
3014 next if length ($word_buf) > 8;
3016 my $salt_len = get_random_num
(1, 9);
3018 $tmp_hash = gen_hash
($mode, $word_buf, substr ($salt_buf, 0, $salt_len));
3020 elsif ($mode == 8600)
3022 next if length ($word_buf) > 16;
3024 $tmp_hash = gen_hash
($mode, $word_buf, "");
3026 elsif ($mode == 8700)
3028 $tmp_hash = gen_hash
($mode, $word_buf, substr ($salt_buf, 0, 5));
3030 elsif ($mode == 9200 || $mode == 9300)
3034 $tmp_hash = gen_hash
($mode, $word_buf, substr ($salt_buf, 0, $salt_len));
3036 elsif ($mode == 9400 || $mode == 9500 || $mode == 9600 || $mode == 9700 || $mode == 9800)
3038 next if length ($word_buf) > 19;
3042 $tmp_hash = gen_hash
($mode, $word_buf, substr ($salt_buf, 0, $salt_len));
3044 elsif ($mode == 10100)
3046 $tmp_hash = gen_hash
($mode, $word_buf, substr ($salt_buf, 0, 32));
3048 elsif ($mode == 10300)
3050 my $salt_len = get_random_num
(4, 15);
3052 $tmp_hash = gen_hash
($mode, $word_buf, substr ($salt_buf, 0, $salt_len));
3054 elsif ($mode == 10400)
3056 next if length ($word_buf) > 31;
3060 $tmp_hash = gen_hash
($mode, $word_buf, substr ($salt_buf, 0, $salt_len));
3062 elsif ($mode == 10500)
3064 next if length ($word_buf) > 15;
3068 $tmp_hash = gen_hash
($mode, $word_buf, substr ($salt_buf, 0, $salt_len));
3070 elsif ($mode == 10600)
3072 next if length ($word_buf) > 31;
3076 $tmp_hash = gen_hash
($mode, $word_buf, substr ($salt_buf, 0, $salt_len));
3078 elsif ($mode == 10700)
3080 next if length ($word_buf) > 15;
3084 $tmp_hash = gen_hash
($mode, $word_buf, substr ($salt_buf, 0, $salt_len));
3086 elsif ($mode == 11000)
3088 $tmp_hash = gen_hash
($mode, $word_buf, substr ($salt_buf, 0, 56));
3090 elsif ($mode == 11300)
3092 $tmp_hash = gen_hash
($mode, $word_buf, substr ($salt_buf, 0, 16));
3094 elsif ($mode == 11400)
3096 next if length ($word_buf) > 24;
3098 my $salt_len = get_random_num
(1, 15);
3100 $tmp_hash = gen_hash
($mode, $word_buf, substr ($salt_buf, 0, $salt_len));
3102 elsif ($mode == 11600)
3104 my $salt_len = get_random_num
(0, 16);
3106 $tmp_hash = gen_hash
($mode, $word_buf, substr ($salt_buf, 0, $salt_len));
3108 elsif ($mode == 12400)
3110 $tmp_hash = gen_hash
($mode, $word_buf, substr ($salt_buf, 0, 4));
3112 elsif ($mode == 12600)
3114 $tmp_hash = gen_hash
($mode, $word_buf, substr ($salt_buf, 0, 64));
3116 elsif ($mode == 12700)
3118 $tmp_hash = gen_hash
($mode, $word_buf, substr ($salt_buf, 0, 32));
3120 elsif ($mode == 12800)
3122 next if length ($word_buf) > 24;
3124 $tmp_hash = gen_hash
($mode, $word_buf, substr ($salt_buf, 0, 20));
3126 elsif ($mode == 12900)
3128 $tmp_hash = gen_hash
($mode, $word_buf, substr ($salt_buf, 0, 32));
3130 elsif ($mode == 13000)
3132 $tmp_hash = gen_hash
($mode, $word_buf, substr ($salt_buf, 0, 32));
3134 elsif ($mode == 13100)
3136 $salt_buf = get_random_kerberos5_tgs_salt
();
3138 $tmp_hash = gen_hash
($mode, $word_buf, $salt_buf);
3140 elsif ($mode == 13200)
3142 $salt_buf = get_random_axcrypt_salt
();
3144 $tmp_hash = gen_hash
($mode, $word_buf, $salt_buf);
3146 elsif ($mode == 13400)
3148 $salt_buf = get_random_keepass_salt
();
3150 $tmp_hash = gen_hash
($mode, $word_buf, $salt_buf);
3152 elsif ($mode == 13500)
3154 $salt_buf = get_pstoken_salt
();
3156 $tmp_hash = gen_hash
($mode, $word_buf, $salt_buf);
3158 elsif ($mode == 13600)
3160 $tmp_hash = gen_hash
($mode, $word_buf, substr ($salt_buf, 0, 32));
3162 elsif ($mode == 13800)
3164 $tmp_hash = gen_hash
($mode, $word_buf, substr ($salt_buf, 0, 256));
3168 print "ERROR: Unsupported hash type\n";
3173 print $tmp_hash, "\n";
3186 for (my $j = 0; $j < scalar @modes; $j++)
3188 my $mode = $modes[$j];
3190 if ($mode == 0 || $mode == 100 || $mode == 101 || $mode == 133 || $mode == 200 || $mode == 300 || $mode == 600 || $mode == 900 || $mode == 1000 || $mode == 1400 || $mode == 1700 || $mode == 2400 || $mode == 2600 || $mode == 3500 || $mode == 4300 || $mode == 4400 || $mode == 4500 || $mode == 4600 || $mode == 4700 || $mode == 5000 || $mode == 5100 || $mode == 5300 || $mode == 5400 || $mode == 6000 || $mode == 6100 || $mode == 6600 || $mode == 6900 || $mode == 5700 || $mode == 8200 || $mode == 8300 || $mode == 9900 || $mode == 10800 || $mode == 11500 || $mode == 13300)
3192 for (my $i = 1; $i < 32; $i++)
3196 rnd
($mode, $len, 0);
3204 elsif ($mode == 10 || $mode == 20 || $mode == 23 || $mode == 30 || $mode == 40 || $mode == 50 || $mode == 60 || $mode == 110 || $mode == 120 || $mode == 121 || $mode == 130 || $mode == 140 || $mode == 150 || $mode == 160 || $mode == 1410 || $mode == 1420 || $mode == 1430 || $mode == 1440 || $mode == 1450 || $mode == 1460 || $mode == 1710 || $mode == 1711 || $mode == 1720 || $mode == 1730 || $mode == 1740 || $mode == 1750 || $mode == 1760 || $mode == 2410 || $mode == 3610 || $mode == 3710 || $mode == 3711 || $mode == 3720 || $mode == 3910 || $mode == 4010 || $mode == 4110 || $mode == 4210 || $mode == 8900 || $mode == 10000 || $mode == 10200 || $mode == 10900 || $mode == 11900 || $mode == 12000 || $mode == 12100)
3206 my $salt_len = get_random_num
(1, 15);
3208 for (my $i = 1; $i < 32; $i++)
3212 rnd
($mode, $len, $salt_len);
3216 rnd
($mode, $i, $salt_len);
3220 elsif ($mode == 11 || $mode == 12 || $mode == 7600 || $mode == 12300)
3222 for (my $i = 1; $i < 32; $i++)
3226 rnd
($mode, $len, 32);
3230 rnd
($mode, $i, 32);
3234 elsif ($mode == 21 || $mode == 22)
3236 for (my $i = 1; $i < 32; $i++)
3240 rnd
($mode, $len, 2);
3248 elsif ($mode == 111 || $mode == 122 || $mode == 125 || $mode == 131 || $mode == 132 || $mode == 400 || $mode == 500 || $mode == 1600 || $mode == 1722 || $mode == 1731 || $mode == 6300 || $mode == 7900 || $mode == 8100 || $mode == 11100)
3250 for (my $i = 1; $i < 32; $i++)
3254 rnd
($mode, $len, 8);
3262 elsif ($mode == 112)
3264 for (my $i = 1; $i < 32; $i++)
3268 rnd
($mode, $len, 20);
3272 rnd
($mode, $i, 20);
3276 elsif ($mode == 141 || $mode == 3300 || $mode == 1441 || $mode == 1800 || $mode == 3200 || $mode == 4800 || $mode == 6400 || $mode == 6500 || $mode == 6700 || $mode == 7400 || $mode == 8000 || $mode == 9100 || $mode == 12200)
3278 for (my $i = 1; $i < 32; $i++)
3282 rnd
($mode, $len, 16);
3286 rnd
($mode, $i, 16);
3292 my $salt_len = get_random_num
(1, 19);
3294 for (my $i = 1; $i < 32; $i++)
3298 rnd
($mode, $len, $salt_len);
3302 rnd
($mode, $i, $salt_len);
3306 elsif ($mode == 1500)
3308 for (my $i = 1; $i < 9; $i++)
3312 rnd
($mode, $len, 2);
3320 elsif ($mode == 2100)
3322 my $salt_len = get_random_num
(1, 19);
3324 for (my $i = 1; $i < 13; $i++)
3328 rnd
($mode, $len, $salt_len);
3332 rnd
($mode, $i, $salt_len);
3336 elsif ($mode == 2500)
3338 my $salt_len = get_random_num
(0, 32);
3340 for (my $i = 8; $i < 16; $i++)
3342 my $generate_from_len = 0;
3351 rnd
($mode, $len, $salt_len);
3355 rnd
($mode, $i, $salt_len);
3359 elsif ($mode == 2611)
3361 for (my $i = 1; $i < 32; $i++)
3365 rnd
($mode, $len, 3);
3373 elsif ($mode == 2612)
3375 my $salt_len = get_random_num
(1, 22);
3377 for (my $i = 1; $i < 32; $i++)
3381 rnd
($mode, $len, $salt_len);
3385 rnd
($mode, $i, $salt_len);
3389 elsif ($mode == 2711)
3391 for (my $i = 1; $i < 32; $i++)
3395 rnd
($mode, $len, 30);
3399 rnd
($mode, $i, 30);
3403 elsif ($mode == 2811)
3405 for (my $i = 1; $i < 32; $i++)
3409 rnd
($mode, $len, 5);
3417 elsif ($mode == 3000)
3419 for (my $i = 1; $i < 8; $i++)
3423 rnd
($mode, $len, 0);
3431 elsif ($mode == 3100)
3433 for (my $i = 1; $i < 32; $i++)
3437 rnd
($mode, $len, 10);
3441 rnd
($mode, $i, 10);
3445 elsif ($mode == 3800 || $mode == 4900)
3447 my $salt_len = get_random_num
(1, 11);
3449 for (my $i = 1; $i < 32; $i++)
3453 rnd
($mode, $len, $salt_len);
3457 rnd
($mode, $i, $salt_len);
3461 elsif ($mode == 5500 || $mode == 5600)
3465 for (my $i = 1; $i < 27; $i++)
3467 $salt_len = get_random_num
(1, 15);
3471 rnd
($mode, $len, $salt_len);
3475 rnd
($mode, $i, $salt_len);
3479 elsif ($mode == 5800)
3481 for (my $i = 1; $i < 14; $i++)
3485 rnd
($mode, $len, 16);
3489 rnd
($mode, $i, 16);
3493 elsif ($mode == 6800)
3495 my $salt_len = get_random_num
(8, 25);
3497 for (my $i = 1; $i < 32; $i++)
3501 rnd
($mode, $len, $salt_len);
3505 rnd
($mode, $i, $salt_len);
3509 elsif ($mode == 7100)
3511 for (my $i = 1; $i < 32; $i++)
3515 rnd
($mode, $len, 64);
3519 rnd
($mode, $i, 64);
3523 elsif ($mode == 7200)
3525 for (my $i = 1; $i < 32; $i++)
3529 rnd
($mode, $len, 128);
3533 rnd
($mode, $i, 128);
3537 elsif ($mode == 7300)
3539 my $salt_len = get_random_num
(32, 255);
3541 for (my $i = 1; $i < 32; $i++)
3545 rnd
($mode, $len, $salt_len);
3549 rnd
($mode, $i, $salt_len);
3553 elsif ($mode == 7500)
3555 for (my $i = 1; $i < 27; $i++)
3559 rnd
($mode, $len, 16);
3563 rnd
($mode, $i, 16);
3567 elsif ($mode == 7700)
3569 my $salt_len = get_random_num
(1, 12);
3571 for (my $i = 1; $i < 9; $i++)
3575 rnd
($mode, $len, $salt_len);
3579 rnd
($mode, $i, $salt_len);
3583 elsif ($mode == 7800)
3585 my $salt_len = get_random_num
(1, 12);
3587 for (my $i = 1; $i < 32; $i++)
3591 rnd
($mode, $len, $salt_len);
3595 rnd
($mode, $i, $salt_len);
3599 elsif ($mode == 8400 || $mode == 11200)
3601 for (my $i = 1; $i < 32; $i++)
3605 rnd
($mode, $len, 40);
3609 rnd
($mode, $i, 40);
3613 elsif ($mode == 8500)
3615 my $salt_len = get_random_num
(1, 8);
3617 for (my $i = 1; $i < 9; $i++)
3621 rnd
($mode, $len, $salt_len);
3625 rnd
($mode, $i, $salt_len);
3629 elsif ($mode == 8600)
3631 for (my $i = 1; $i < 17; $i++)
3635 rnd
($mode, $len, 0);
3643 elsif ($mode == 8700)
3645 for (my $i = 1; $i < 32; $i++)
3649 rnd
($mode, $len, 5);
3657 elsif ($mode == 9200 || $mode == 9300)
3661 for (my $i = 1; $i < 32; $i++)
3665 rnd
($mode, $len, $salt_len);
3669 rnd
($mode, $i, $salt_len);
3673 elsif ($mode == 9400 || $mode == 9500 || $mode == 9600 || $mode == 9700 || $mode == 9800)
3677 for (my $i = 1; $i < 20; $i++)
3681 rnd
($mode, $len, $salt_len);
3685 rnd
($mode, $i, $salt_len);
3689 elsif ($mode == 10100)
3691 for (my $i = 1; $i < 32; $i++)
3695 rnd
($mode, $len, 32);
3699 rnd
($mode, $i, 32);
3703 elsif ($mode == 10300)
3705 my $salt_len = get_random_num
(4, 15);
3707 for (my $i = 1; $i < 32; $i++)
3711 rnd
($mode, $len, $salt_len);
3715 rnd
($mode, $i, $salt_len);
3719 elsif ($mode == 10400 || $mode == 10600)
3723 for (my $i = 1; $i < 32; $i++)
3727 rnd
($mode, $len, $salt_len);
3731 rnd
($mode, $i, $salt_len);
3735 elsif ($mode == 10500 || $mode == 10700)
3739 for (my $i = 1; $i < 16; $i++)
3743 rnd
($mode, $len, $salt_len);
3747 rnd
($mode, $i, $salt_len);
3751 elsif ($mode == 11000)
3753 for (my $i = 1; $i < 32; $i++)
3757 rnd
($mode, $len, 56);
3761 rnd
($mode, $i, 56);
3765 elsif ($mode == 11300)
3767 for (my $i = 1; $i < 32; $i++)
3771 rnd
($mode, $len, 16);
3775 rnd
($mode, $i, 16);
3779 elsif ($mode == 11400)
3781 for (my $i = 1; $i < 24; $i++)
3785 rnd
($mode, $len, 16);
3789 rnd
($mode, $i, 16);
3793 elsif ($mode == 11600)
3795 my $salt_len = get_random_num
(0, 16);
3797 for (my $i = 1; $i < 32; $i++)
3801 rnd
($mode, $len, $salt_len);
3805 rnd
($mode, $i, $salt_len);
3809 elsif ($mode == 12400)
3811 for (my $i = 1; $i < 32; $i++)
3815 rnd
($mode, $len, 4);
3823 elsif ($mode == 12600)
3825 for (my $i = 1; $i < 32; $i++)
3829 rnd
($mode, $len, 64);
3833 rnd
($mode, $i, 64);
3837 elsif ($mode == 12700)
3839 for (my $i = 1; $i < 32; $i++)
3843 rnd
($mode, $len, 32);
3847 rnd
($mode, $i, 32);
3851 elsif ($mode == 12800)
3853 for (my $i = 1; $i < 25; $i++)
3857 rnd
($mode, $len, 20);
3861 rnd
($mode, $i, 20);
3865 elsif ($mode == 12900)
3867 for (my $i = 1; $i < 32; $i++)
3871 rnd
($mode, $len, 32);
3875 rnd
($mode, $i, 32);
3879 elsif ($mode == 13000)
3881 for (my $i = 1; $i < 32; $i++)
3885 rnd
($mode, $len, 32);
3889 rnd
($mode, $i, 32);
3893 elsif ($mode == 13100)
3895 for (my $i = 1; $i < 27; $i++)
3899 rnd
($mode, $len, 16);
3903 rnd
($mode, $i, 16);
3907 elsif ($mode == 13200)
3909 for (my $i = 1; $i < 32; $i++)
3913 rnd
($mode, $len, 32);
3917 rnd
($mode, $i, 32);
3921 elsif ($mode == 13400)
3923 for (my $i = 1; $i < 16; $i++)
3927 rnd
($mode, $len, 16);
3931 rnd
($mode, $i, 16);
3935 elsif ($mode == 13500)
3937 for (my $i = 1; $i < 16; $i++)
3941 rnd
($mode, $len, 16);
3945 rnd
($mode, $i, 16);
3949 elsif ($mode == 13600)
3951 for (my $i = 1; $i < 16; $i++)
3955 rnd
($mode, $len, 32);
3959 rnd
($mode, $i, 32);
3963 elsif ($mode == 13800)
3965 for (my $i = 1; $i < 32; $i++)
3969 rnd
($mode, $len, 256);
3973 rnd
($mode, $i, 256);
3986 my $word_buf = shift;
3988 my $salt_buf = shift;
3992 my $additional_param = shift;
3994 my $additional_param2 = shift;
3996 my $additional_param3 = shift;
3998 my $additional_param4 = shift;
4000 my $additional_param5 = shift;
4002 my $additional_param6 = shift;
4004 my $additional_param7 = shift;
4006 my $additional_param8 = shift;
4008 my $additional_param9 = shift;
4010 my $additional_param10 = shift;
4012 my $additional_param11 = shift;
4024 $hash_buf = md5_hex
($word_buf);
4026 $tmp_hash = sprintf ("%s", $hash_buf);
4030 $hash_buf = md5_hex
($word_buf . $salt_buf);
4032 $tmp_hash = sprintf ("%s:%s", $hash_buf, $salt_buf);
4036 $hash_buf = md5_hex
($word_buf . $salt_buf);
4038 $tmp_hash = sprintf ("%s:%s", $hash_buf, $salt_buf);
4042 $hash_buf = md5_hex
($word_buf . $salt_buf);
4044 $tmp_hash = sprintf ("%s:%s", $hash_buf, $salt_buf);
4048 $hash_buf = md5_hex
($salt_buf . $word_buf);
4050 $tmp_hash = sprintf ("%s:%s", $hash_buf, $salt_buf);
4054 $hash_buf = md5_hex
($salt_buf . $word_buf);
4056 $tmp_hash = sprintf ("%s:%s", $hash_buf, $salt_buf);
4060 my $itoa64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
4061 my $salt_suffix = "Administration Tools";
4063 my $pass = sprintf ("%s:%s:%s", $salt_buf, $salt_suffix, $word_buf);
4065 $hash_buf = md5
($pass);
4069 for (my $pos = 0; $pos < 16; $pos += 2)
4071 my $octet1 = ord (substr ($hash_buf, $pos + 0, 1));
4072 my $octet2 = ord (substr ($hash_buf, $pos + 1, 1));
4074 my $num = ($octet1 <<8 & 0xff00) | ($octet2 & 0xff);
4076 my $idx1 = $num >> 12 & 0x0f;
4077 my $idx2 = $num >> 6 & 0x3f;
4078 my $idx3 = $num & 0x3f;
4080 $res = $res . substr ($itoa64, $idx1, 1) . substr ($itoa64, $idx2, 1) . substr ($itoa64, $idx3, 1);
4083 my $obfuscate_str = "nrcstn";
4084 my @obfuscate_pos = (0, 6, 12, 17, 23, 29);
4086 foreach my $pos (keys @obfuscate_pos)
4088 my $idx = $obfuscate_pos[$pos];
4089 my $before = substr ($res, 0, $idx);
4090 my $char = substr ($obfuscate_str, $pos, 1);
4091 my $after = substr ($res, $idx);
4093 $res = sprintf ("%s%s%s", $before, $char, $after);
4096 $tmp_hash = sprintf ("%s:%s", $res, $salt_buf);
4100 $hash_buf = md5_hex
($salt_buf . "\nskyper\n" . $word_buf);
4102 $tmp_hash = sprintf ("%s:%s", $hash_buf, $salt_buf);
4106 $hash_buf = md5_hex
(encode
("UTF-16LE", $word_buf) . $salt_buf);
4108 $tmp_hash = sprintf ("%s:%s", $hash_buf, $salt_buf);
4112 $hash_buf = md5_hex
($salt_buf . encode
("UTF-16LE", $word_buf));
4114 $tmp_hash = sprintf ("%s:%s", $hash_buf, $salt_buf);
4118 $hash_buf = hmac_hex
($salt_buf, $word_buf, \
&md5
, 64);
4120 $tmp_hash = sprintf ("%s:%s", $hash_buf, $salt_buf);
4124 $hash_buf = hmac_hex
($word_buf, $salt_buf, \
&md5
, 64);
4126 $tmp_hash = sprintf ("%s:%s", $hash_buf, $salt_buf);
4128 elsif ($mode == 100)
4130 $hash_buf = sha1_hex
($word_buf);
4132 $tmp_hash = sprintf ("%s", $hash_buf);
4134 elsif ($mode == 101)
4136 $hash_buf = sha1
($word_buf);
4138 my $base64_buf = encode_base64
($hash_buf);
4140 chomp ($base64_buf);
4142 $tmp_hash = sprintf ("{SHA}%s", $base64_buf);
4144 elsif ($mode == 110)
4146 $hash_buf = sha1_hex
($word_buf . $salt_buf);
4148 $tmp_hash = sprintf ("%s:%s", $hash_buf, $salt_buf);
4150 elsif ($mode == 111)
4152 $hash_buf = sha1
($word_buf . $salt_buf);
4154 my $base64_buf = encode_base64
($hash_buf . $salt_buf);
4156 chomp ($base64_buf);
4158 $tmp_hash = sprintf ("{SSHA}%s", $base64_buf);
4160 elsif ($mode == 112)
4162 my $salt_buf_bin = pack ("H*", $salt_buf);
4164 $hash_buf = sha1_hex
($word_buf . $salt_buf_bin);
4166 $tmp_hash = sprintf ("%s:%s", $hash_buf, $salt_buf);
4168 elsif ($mode == 120)
4170 $hash_buf = sha1_hex
($salt_buf . $word_buf);
4172 $tmp_hash = sprintf ("%s:%s", $hash_buf, $salt_buf);
4174 elsif ($mode == 121)
4176 $hash_buf = sha1_hex
(lc ($salt_buf) . $word_buf);
4178 $tmp_hash = sprintf ("%s:%s", $hash_buf, $salt_buf);
4180 elsif ($mode == 122)
4182 my $salt_buf_bin = pack ("H*", $salt_buf);
4184 $hash_buf = sha1_hex
($salt_buf_bin . $word_buf);
4186 $tmp_hash = sprintf ("%s%s", $salt_buf, $hash_buf);
4188 elsif ($mode == 125)
4190 my $signature = "01";
4192 my $salt_buf_bin = pack ("H*", $salt_buf . $signature);
4194 $hash_buf = sha1_hex
($salt_buf_bin . $word_buf);
4196 $tmp_hash = sprintf ("%s%s%s", $salt_buf, $signature, $hash_buf);
4198 elsif ($mode == 130)
4200 $hash_buf = sha1_hex
(encode
("UTF-16LE", $word_buf) . $salt_buf);
4202 $tmp_hash = sprintf ("%s:%s", $hash_buf, $salt_buf);
4204 elsif ($mode == 131)
4206 my $salt_buf_bin = pack ("H*", $salt_buf);
4208 $hash_buf = sha1_hex
(encode
("UTF-16LE", uc ($word_buf)) . $salt_buf_bin);
4210 $tmp_hash = sprintf ("0x0100%s%s%s", $salt_buf, "0" x
40, $hash_buf);
4212 elsif ($mode == 132)
4214 my $salt_buf_bin = pack ("H*", $salt_buf);
4216 $hash_buf = sha1_hex
(encode
("UTF-16LE", $word_buf) . $salt_buf_bin);
4218 $tmp_hash = sprintf ("0x0100%s%s", $salt_buf, $hash_buf);
4220 elsif ($mode == 133)
4222 $hash_buf = sha1
(encode
("UTF-16LE", $word_buf));
4224 $hash_buf = encode_base64
($hash_buf);
4225 $hash_buf =~ s/[\r\n]//g;
4227 $tmp_hash = sprintf ("%s", $hash_buf);
4229 elsif ($mode == 140)
4231 $hash_buf = sha1_hex
($salt_buf . encode
("UTF-16LE", $word_buf));
4233 $tmp_hash = sprintf ("%s:%s", $hash_buf, $salt_buf);
4235 elsif ($mode == 141)
4237 $hash_buf = sha1
($salt_buf . encode
("UTF-16LE", $word_buf));
4239 my $base64_salt_buf = encode_base64
($salt_buf);
4241 chomp ($base64_salt_buf);
4243 my $base64_hash_buf = encode_base64
($hash_buf);
4245 $base64_hash_buf = substr ($base64_hash_buf, 0, 27);
4247 $tmp_hash = sprintf ("\$episerver\$*0*%s*%s", $base64_salt_buf, $base64_hash_buf);
4249 elsif ($mode == 150)
4251 $hash_buf = hmac_hex
($salt_buf, $word_buf, \
&sha1
, 64);
4253 $tmp_hash = sprintf ("%s:%s", $hash_buf, $salt_buf);
4255 elsif ($mode == 160)
4257 $hash_buf = hmac_hex
($word_buf, $salt_buf, \
&sha1
, 64);
4259 $tmp_hash = sprintf ("%s:%s", $hash_buf, $salt_buf);
4261 elsif ($mode == 200)
4263 my $ppr = Authen
::Passphrase
::MySQL323
->new (passphrase
=> $word_buf);
4265 $hash_buf = $ppr->hash_hex;
4267 $tmp_hash = sprintf ("%s", $hash_buf);
4269 elsif ($mode == 300)
4271 $hash_buf = substr (password41
($word_buf), 1);
4273 $hash_buf = lc ($hash_buf); # useful for 'not matched' check only
4275 $tmp_hash = sprintf ("%s", $hash_buf);
4277 elsif ($mode == 400)
4286 my $ppr = Authen
::Passphrase
::PHPass
->new
4290 passphrase
=> $word_buf,
4293 $hash_buf = $ppr->as_rfc2307;
4295 $tmp_hash = sprintf ("%s", substr ($hash_buf, 7));
4297 elsif ($mode == 500)
4299 my $iterations = 1000;
4301 if (defined ($iter))
4305 $iterations = int ($iter);
4309 $hash_buf = md5_crypt
('$1$', $iterations, $word_buf, $salt_buf);
4311 $tmp_hash = sprintf ("%s", $hash_buf);
4313 elsif ($mode == 900)
4315 $hash_buf = md4_hex
($word_buf);
4317 $tmp_hash = sprintf ("%s", $hash_buf);
4319 elsif ($mode == 1000)
4321 $hash_buf = md4_hex
(encode
("UTF-16LE", $word_buf));
4323 $tmp_hash = sprintf ("%s", $hash_buf);
4325 elsif ($mode == 1100)
4327 $hash_buf = md4_hex
(md4
(encode
("UTF-16LE", $word_buf)) . encode
("UTF-16LE", lc ($salt_buf)));
4329 $tmp_hash = sprintf ("%s:%s", $hash_buf, $salt_buf);
4331 elsif ($mode == 1400)
4333 $hash_buf = sha256_hex
($word_buf);
4335 $tmp_hash = sprintf ("%s", $hash_buf);
4337 elsif ($mode == 1410)
4339 $hash_buf = sha256_hex
($word_buf . $salt_buf);
4341 $tmp_hash = sprintf ("%s:%s", $hash_buf, $salt_buf);
4343 elsif ($mode == 1420)
4345 $hash_buf = sha256_hex
($salt_buf . $word_buf);
4347 $tmp_hash = sprintf ("%s:%s", $hash_buf, $salt_buf);
4349 elsif ($mode == 1430)
4351 $hash_buf = sha256_hex
(encode
("UTF-16LE", $word_buf) . $salt_buf);
4353 $tmp_hash = sprintf ("%s:%s", $hash_buf, $salt_buf);
4355 elsif ($mode == 1440)
4357 $hash_buf = sha256_hex
($salt_buf . encode
("UTF-16LE", $word_buf));
4359 $tmp_hash = sprintf ("%s:%s", $hash_buf, $salt_buf);
4361 elsif ($mode == 1441)
4363 $hash_buf = sha256
($salt_buf . encode
("UTF-16LE", $word_buf));
4365 my $base64_salt_buf = encode_base64
($salt_buf);
4367 chomp ($base64_salt_buf);
4369 my $base64_hash_buf = encode_base64
($hash_buf);
4371 chomp ($base64_hash_buf);
4373 $base64_hash_buf = substr ($base64_hash_buf, 0, 43);
4375 $tmp_hash = sprintf ("\$episerver\$*1*%s*%s", $base64_salt_buf, $base64_hash_buf);
4377 elsif ($mode == 1450)
4379 $hash_buf = hmac_hex
($salt_buf, $word_buf, \
&sha256
, 64);
4381 $tmp_hash = sprintf ("%s:%s", $hash_buf, $salt_buf);
4383 elsif ($mode == 1460)
4385 $hash_buf = hmac_hex
($word_buf, $salt_buf, \
&sha256
, 64);
4387 $tmp_hash = sprintf ("%s:%s", $hash_buf, $salt_buf);
4389 elsif ($mode == 1500)
4391 $hash_buf = crypt ($word_buf, $salt_buf);
4393 $tmp_hash = sprintf ("%s", $hash_buf);
4395 elsif ($mode == 1600)
4397 my $iterations = 1000;
4399 if (defined ($iter))
4403 $iterations = int ($iter);
4407 $hash_buf = md5_crypt
('$apr1$', $iterations, $word_buf, $salt_buf);
4409 $tmp_hash = sprintf ("%s", $hash_buf);
4411 elsif ($mode == 1700)
4413 $hash_buf = sha512_hex
($word_buf);
4415 $tmp_hash = sprintf ("%s", $hash_buf);
4417 elsif ($mode == 1710)
4419 $hash_buf = sha512_hex
($word_buf . $salt_buf);
4421 $tmp_hash = sprintf ("%s:%s", $hash_buf, $salt_buf);
4423 elsif ($mode == 1711)
4425 $hash_buf = sha512_hex
($word_buf . $salt_buf);
4427 my $base64_buf = encode_base64
(pack ("H*", $hash_buf) . $salt_buf);
4429 $base64_buf =~ s/[ \n]//g;
4431 $tmp_hash = sprintf ("{SSHA512}%s", $base64_buf);
4433 elsif ($mode == 1720)
4435 $hash_buf = sha512_hex
($salt_buf . $word_buf);
4437 $tmp_hash = sprintf ("%s:%s", $hash_buf, $salt_buf);
4439 elsif ($mode == 1730)
4441 $hash_buf = sha512_hex
(encode
("UTF-16LE", $word_buf) . $salt_buf);
4443 $tmp_hash = sprintf ("%s:%s", $hash_buf, $salt_buf);
4445 elsif ($mode == 1740)
4447 $hash_buf = sha512_hex
($salt_buf . encode
("UTF-16LE", $word_buf));
4449 $tmp_hash = sprintf ("%s:%s", $hash_buf, $salt_buf);
4451 elsif ($mode == 1722)
4453 my $salt_buf_bin = pack ("H*", $salt_buf);
4455 $hash_buf = sha512_hex
($salt_buf_bin . $word_buf);
4457 $tmp_hash = sprintf ("%s%s", $salt_buf, $hash_buf);
4459 elsif ($mode == 1731)
4461 my $salt_buf_bin = pack ("H*", $salt_buf);
4463 $hash_buf = sha512_hex
(encode
("UTF-16LE", $word_buf) . $salt_buf_bin);
4465 $tmp_hash = sprintf ("0x0200%s%s", $salt_buf, $hash_buf);
4467 elsif ($mode == 1750)
4469 $hash_buf = hmac_hex
($salt_buf, $word_buf, \
&sha512
, 128);
4471 $tmp_hash = sprintf ("%s:%s", $hash_buf, $salt_buf);
4473 elsif ($mode == 1760)
4475 $hash_buf = hmac_hex
($word_buf, $salt_buf, \
&sha512
, 128);
4477 $tmp_hash = sprintf ("%s:%s", $hash_buf, $salt_buf);
4479 elsif ($mode == 1800)
4481 my $iterations = 5000;
4483 if (defined ($iter))
4487 $iterations = int ($iter);
4491 $hash_buf = sha512_crypt
($iterations, $word_buf, $salt_buf);
4493 $tmp_hash = sprintf ("%s", $hash_buf);
4495 elsif ($mode == 2100)
4497 my $iterations = 10240;
4501 $iterations = int ($iter);
4504 my $salt = encode
("UTF-16LE", lc ($salt_buf));
4506 my $pbkdf2 = Crypt
::PBKDF2
->new
4508 hash_class
=> 'HMACSHA1',
4509 iterations
=> $iterations,
4511 salt_len
=> length ($salt),
4514 $hash_buf = unpack ("H*", $pbkdf2->PBKDF2 ($salt, md4
(md4
(encode
("UTF-16LE", $word_buf)) . $salt)));
4516 $tmp_hash = sprintf ("\$DCC2\$%i#%s#%s", $iterations, $salt_buf, $hash_buf);
4518 elsif ($mode == 2400)
4520 $tmp_hash = sprintf ("%s", pseudo_base64
(Digest
::MD5
::md5
($word_buf . "\0" x
(16 - length ($word_buf)))));
4522 elsif ($mode == 2410)
4524 my $salt_len = length ($salt_buf);
4526 my $salt_len_max4 = ($salt_len < 4) ?
$salt_len : 4;
4528 my $hash_buf = pseudo_base64
(Digest
::MD5
::md5
($word_buf . substr ($salt_buf, 0, $salt_len_max4) . "\0" x
(16 - length ($word_buf) - $salt_len_max4)));
4530 $tmp_hash = sprintf ("%s:%s", $hash_buf, $salt_buf);
4532 elsif ($mode == 2500)
4534 my ($bssid, $stmac, $snonce, $anonce, $eapol, $keyver, $eapol_size);
4536 if (! defined ($additional_param))
4540 $bssid = randbytes
(6);
4541 $stmac = randbytes
(6);
4542 $snonce = randbytes
(32);
4543 $anonce = randbytes
(32);
4545 $keyver = get_random_num
(1, 3); # 1 or 2
4548 # should be "validly" generated, but in theory could be anything for us also:
4549 # $eapol = "\x00" x 121; # works too, but let's generate it correctly
4551 $eapol = gen_random_wpa_eapol
($keyver, $snonce);
4555 $bssid = $additional_param;
4556 $stmac = $additional_param2;
4557 $snonce = $additional_param3;
4558 $anonce = $additional_param4;
4559 $keyver = $additional_param5;
4560 $eapol = $additional_param6;
4563 $eapol_size = length ($eapol);
4567 my $iterations = 4096;
4573 # generate the Pairwise Master Key (PMK)
4575 my $pbkdf2 = Crypt
::PBKDF2
->new
4577 hash_class
=> 'HMACSHA1',
4578 iterations
=> $iterations,
4582 my $pmk = $pbkdf2->PBKDF2 ($salt_buf, $word_buf);
4584 # Pairwise Transient Key (PTK) transformation
4586 my $ptk = wpa_prf_512
($pmk, $stmac, $bssid, $snonce, $anonce);
4588 # generate the Message Integrity Code (MIC)
4592 if ($keyver == 1) # WPA1 => MD5
4594 $mic = hmac
($eapol, $ptk, \
&md5
);
4598 $mic = hmac
($eapol, $ptk, \
&sha1
);
4601 $mic = substr ($mic, 0, 16);
4604 # format the binary output
4609 # first the essid (NULL-padded up to the first 36 bytes)
4611 $hash_buf .= $salt_buf;
4612 $hash_buf .= "\x00" x
(36 - length ($salt_buf));
4614 # the 2 MAC addresses
4616 $hash_buf .= $bssid;
4617 $hash_buf .= $stmac;
4621 $hash_buf .= $snonce;
4622 $hash_buf .= $anonce;
4626 $hash_buf .= $eapol;
4627 $hash_buf .= "\x00" x
(256 - $eapol_size);
4631 $hash_buf .= pack ("L*", $eapol_size);
4635 $hash_buf .= pack ("L*", $keyver);
4637 # and finally: the key mic
4641 # base64 encode the output
4643 $tmp_hash = encode_base64
($hash_buf, '');
4645 elsif ($mode == 2600)
4647 $hash_buf = md5_hex
(md5_hex
($word_buf));
4649 $tmp_hash = sprintf ("%s", $hash_buf);
4651 elsif ($mode == 2611)
4653 $hash_buf = md5_hex
(md5_hex
($word_buf) . $salt_buf);
4655 $tmp_hash = sprintf ("%s:%s", $hash_buf, $salt_buf);
4657 elsif ($mode == 2612)
4659 my $salt_buf_hex = unpack ("H*", $salt_buf);
4661 $hash_buf = md5_hex
(md5_hex
($word_buf) . $salt_buf);
4663 $tmp_hash = sprintf ("\$PHPS\$%s\$%s", $salt_buf_hex, $hash_buf);
4665 elsif ($mode == 2711)
4667 $hash_buf = md5_hex
(md5_hex
($word_buf) . $salt_buf);
4669 $tmp_hash = sprintf ("%s:%s", $hash_buf, $salt_buf);
4671 elsif ($mode == 2811)
4673 $hash_buf = md5_hex
(md5_hex
($salt_buf) . md5_hex
($word_buf));
4675 $tmp_hash = sprintf ("%s:%s", $hash_buf, $salt_buf);
4677 elsif ($mode == 3000)
4679 my $ppr = Authen
::Passphrase
::LANManager
->new ("passphrase" => $word_buf);
4681 $hash_buf = $ppr->hash_hex;
4683 $tmp_hash = sprintf ("%s", substr ($hash_buf, 0, 16));
4685 elsif ($mode == 3100)
4687 $hash_buf = oracle_hash
($salt_buf, $word_buf);
4689 $tmp_hash = sprintf ("%s:%s", $hash_buf, $salt_buf);
4691 elsif ($mode == 3200)
4700 $tmp_hash = bcrypt
($word_buf, sprintf ('$2a$%s$%s$', $cost, en_base64
($salt_buf)));
4702 elsif ($mode == 3300)
4704 my $iterations = 904;
4708 $iterations = int ($iter);
4713 if (defined ($additional_param))
4715 $variant = $additional_param;
4718 my $prefix = sprintf ("\$md5%srounds=%i\$%s", $variant, $iterations, $salt_buf);
4720 $iterations += 4096;
4722 $hash_buf = sun_md5
($word_buf, $prefix, $iterations);
4724 $tmp_hash = sprintf ("%s\$%s", $prefix, $hash_buf);
4726 elsif ($mode == 3500)
4728 $hash_buf = md5_hex
(md5_hex
(md5_hex
($word_buf)));
4730 $tmp_hash = sprintf ("%s", $hash_buf);
4732 elsif ($mode == 3610)
4734 $hash_buf = md5_hex
(md5_hex
($salt_buf) . $word_buf);
4736 $tmp_hash = sprintf ("%s:%s", $hash_buf, $salt_buf);
4738 elsif ($mode == 3710)
4740 $hash_buf = md5_hex
($salt_buf . md5_hex
($word_buf));
4742 $tmp_hash = sprintf ("%s:%s", $hash_buf, $salt_buf);
4744 elsif ($mode == 3711)
4746 $hash_buf = md5_hex
($salt_buf . "-" . md5_hex
($word_buf));
4748 $tmp_hash = sprintf ("\$B\$%s\$%s", $salt_buf, $hash_buf);
4750 elsif ($mode == 3720)
4752 $hash_buf = md5_hex
($word_buf . md5_hex
($salt_buf));
4754 $tmp_hash = sprintf ("%s:%s", $hash_buf, $salt_buf);
4756 elsif ($mode == 3800)
4758 $hash_buf = md5_hex
($salt_buf . $word_buf . $salt_buf);
4760 $tmp_hash = sprintf ("%s:%s", $hash_buf, $salt_buf);
4762 elsif ($mode == 3910)
4764 $hash_buf = md5_hex
(md5_hex
($word_buf) . md5_hex
($salt_buf));
4766 $tmp_hash = sprintf ("%s:%s", $hash_buf, $salt_buf);
4768 elsif ($mode == 4010)
4770 $hash_buf = md5_hex
($salt_buf . md5_hex
($salt_buf . $word_buf));
4772 $tmp_hash = sprintf ("%s:%s", $hash_buf, $salt_buf);
4774 elsif ($mode == 4110)
4776 $hash_buf = md5_hex
($salt_buf . md5_hex
($word_buf . $salt_buf));
4778 $tmp_hash = sprintf ("%s:%s", $hash_buf, $salt_buf);
4780 elsif ($mode == 4210)
4782 $hash_buf = md5_hex
($salt_buf . "\x00" . $word_buf);
4784 $tmp_hash = sprintf ("%s:%s", $hash_buf, $salt_buf);
4786 elsif ($mode == 4300)
4788 $hash_buf = md5_hex
(uc (md5_hex
($word_buf)));
4790 $tmp_hash = sprintf ("%s", $hash_buf);
4792 elsif ($mode == 4400)
4794 $hash_buf = md5_hex
(sha1_hex
($word_buf));
4796 $tmp_hash = sprintf ("%s", $hash_buf);
4798 elsif ($mode == 4500)
4800 $hash_buf = sha1_hex
(sha1_hex
($word_buf));
4802 $tmp_hash = sprintf ("%s", $hash_buf);
4804 elsif ($mode == 4600)
4806 $hash_buf = sha1_hex
(sha1_hex
(sha1_hex
($word_buf)));
4808 $tmp_hash = sprintf ("%s", $hash_buf);
4810 elsif ($mode == 4700)
4812 $hash_buf = sha1_hex
(md5_hex
($word_buf));
4814 $tmp_hash = sprintf ("%s", $hash_buf);
4816 elsif ($mode == 4800)
4818 my $index = rindex ($salt_buf, ":");
4820 my $salt = substr ($salt_buf, 0, $index);
4821 my $salt_bin = pack ("H*", $salt);
4822 my $chap_sign = substr ($salt_buf, $index + 1);
4823 my $chap_sign_bin = pack ("H*", $chap_sign);
4825 $hash_buf = md5_hex
($chap_sign_bin . $word_buf . $salt_bin);
4827 $tmp_hash = sprintf ("%s:%s", $hash_buf, $salt_buf);
4829 elsif ($mode == 4900)
4831 $hash_buf = sha1_hex
($salt_buf . $word_buf . $salt_buf);
4833 $tmp_hash = sprintf ("%s:%s", $hash_buf, $salt_buf);
4835 elsif ($mode == 5000)
4837 $hash_buf = keccak_256_hex
($word_buf);
4839 $tmp_hash = sprintf ("%s", $hash_buf);
4841 elsif ($mode == 5100)
4845 if (! defined ($additional_param))
4851 $pos = $additional_param * 8 unless ($additional_param > 2);
4854 $hash_buf = md5_hex
($word_buf);
4856 $tmp_hash = sprintf ("%s", substr ($hash_buf, $pos, 16));
4858 elsif ($mode == 5300)
4860 my @salt_arr = split (":", $salt_buf);
4862 my $msg_buf = pack ("H*", $salt_arr[0] . $salt_arr[1] . $salt_arr[2] . $salt_arr[3] . $salt_arr[4] . $salt_arr[5]);
4863 my $nr_buf = pack ("H*", $salt_arr[6] . $salt_arr[7]);
4865 my $hash_buf = hmac
($nr_buf , $word_buf, \
&md5
, 64);
4866 $hash_buf = hmac_hex
($msg_buf, $hash_buf, \
&md5
, 64);
4868 $tmp_hash = sprintf ("%s:%s", $salt_buf, $hash_buf);
4870 elsif ($mode == 5400)
4872 my @salt_arr = split (":", $salt_buf);
4874 my $msg_buf = pack ("H*", $salt_arr[0] . $salt_arr[1] . $salt_arr[2] . $salt_arr[3] . $salt_arr[4] . $salt_arr[5]);
4875 my $nr_buf = pack ("H*", $salt_arr[6] . $salt_arr[7]);
4877 my $hash_buf = hmac
($nr_buf , $word_buf, \
&sha1
, 64);
4878 $hash_buf = hmac_hex
($msg_buf, $hash_buf, \
&sha1
, 64);
4880 $tmp_hash = sprintf ("%s:%s", $salt_buf, $hash_buf);
4882 elsif ($mode == 5500)
4884 my $index1 = index ($salt_buf, "::");
4885 my $user = substr ($salt_buf, 0, $index1);
4887 my $index2 = index ($salt_buf, ":", $index1 + 2);
4888 my $domain = substr ($salt_buf, $index1 + 2, $index2 - $index1 - 2);
4890 my $len = length (substr ($salt_buf, $index2 + 1));
4892 my $c_challenge_hex;
4896 $c_challenge_hex = substr ($salt_buf, $index2 + 1, 48);
4901 $c_challenge_hex = substr ($salt_buf, $index2 + 1, 16);
4902 $c_challenge_hex .= 00 x
32;
4905 my $c_challenge = pack ("H*", substr ($c_challenge_hex, 0, 16));
4906 my $s_challenge_hex = substr ($salt_buf, $index2 + 17, 16);
4907 my $s_challenge = pack ("H*", $s_challenge_hex);
4909 my $challenge = substr (md5
($s_challenge . $c_challenge), 0, 8);
4913 my $nthash = Authen
::Passphrase
::NTHash
->new (passphrase
=> $word_buf)->hash . "\x00" x
5;
4915 $ntresp .= Crypt
::ECB
::encrypt
(setup_des_key
(substr ($nthash, 0, 7)), "DES", $challenge, "none");
4916 $ntresp .= Crypt
::ECB
::encrypt
(setup_des_key
(substr ($nthash, 7, 7)), "DES", $challenge, "none");
4917 $ntresp .= Crypt
::ECB
::encrypt
(setup_des_key
(substr ($nthash, 14, 7)), "DES", $challenge, "none");
4919 $tmp_hash = sprintf ("%s::%s:%s:%s:%s", $user, $domain, $c_challenge_hex, unpack ("H*", $ntresp), $s_challenge_hex);
4921 elsif ($mode == 5600)
4923 my $index1 = index ($salt_buf, "::");
4924 my $user = substr ($salt_buf, 0, $index1);
4926 my $index2 = index ($salt_buf, ":", $index1 + 2);
4927 my $domain = substr ($salt_buf, $index1 + 2, $index2 - $index1 - 2);
4929 my $s_challenge_hex = substr ($salt_buf, $index2 + 1, 16);
4930 my $s_challenge = pack ("H*", $s_challenge_hex);
4932 my $temp_hex = substr ($salt_buf, $index2 + 17);
4933 my $temp = pack ("H*", $temp_hex);
4935 my $nthash = Authen
::Passphrase
::NTHash
->new (passphrase
=> $word_buf)->hash;
4936 my $identity = Encode
::encode
("UTF-16LE", uc ($user) . $domain);
4938 $hash_buf = hmac_hex
($s_challenge . $temp, hmac
($identity, $nthash, \
&md5
, 64), \
&md5
, 64);
4940 $tmp_hash = sprintf ("%s::%s:%s:%s:%s", $user, $domain, $s_challenge_hex, $hash_buf, $temp_hex);
4942 elsif ($mode == 5700)
4944 $hash_buf = sha256
($word_buf);
4946 my $base64_buf = encode_base64
($hash_buf);
4950 for (my $i = 0; $i < 43; $i++)
4952 $tmp_hash .= $CISCO_BASE64_MAPPING->{substr ($base64_buf, $i, 1)};
4955 elsif ($mode == 5800)
4957 $hash_buf = androidpin_hash
($word_buf, $salt_buf);
4959 $tmp_hash = sprintf ("%s:%s", $hash_buf, $salt_buf);
4961 elsif ($mode == 6000)
4963 $hash_buf = ripemd160_hex
($word_buf);
4965 $tmp_hash = sprintf ("%s", $hash_buf);
4967 elsif ($mode == 6100)
4969 $hash_buf = whirlpool_hex
($word_buf);
4971 $tmp_hash = sprintf ("%s", $hash_buf);
4973 elsif ($mode == 6300)
4975 my $iterations = 1000; # hard coded by the AIX format
4977 $hash_buf = md5_crypt
('', $iterations, $word_buf, $salt_buf);
4979 $tmp_hash = sprintf ("{smd5}%s", $hash_buf);
4981 elsif ($mode == 6400)
4983 my $iterations = 64;
4987 $iterations = 1 << int ($iter);
4990 $hash_buf = aix_ssha256_pbkdf2
($word_buf, $salt_buf, $iterations);
4992 $tmp_hash = sprintf ("{ssha256}%02i\$%s\$%s", log ($iterations) / log (2), $salt_buf, $hash_buf);
4994 elsif ($mode == 6500)
4996 my $iterations = 64;
5000 $iterations = 1 << int ($iter);
5003 $hash_buf = aix_ssha512_pbkdf2
($word_buf, $salt_buf, $iterations);
5005 $tmp_hash = sprintf ("{ssha512}%02i\$%s\$%s", log ($iterations) / log (2), $salt_buf, $hash_buf);
5007 elsif ($mode == 6600)
5009 my $iterations = 1000;
5013 $iterations = int ($iter);
5016 my $salt_hex = substr ($salt_buf, 0, 16);
5017 my $salt = pack ("H*", $salt_hex);
5019 my $prefix = substr ($salt_buf, 16, 2016);
5021 my $iv_hex = substr ($salt_buf, 2032);
5022 my $iv = pack ("H*", $iv_hex);
5024 my $data = pack ("H*", "10101010101010101010101010101010");
5026 my $hasher = Crypt
::PBKDF2
->hasher_from_algorithm ('HMACSHA1');
5028 my $pbkdf2 = Crypt
::PBKDF2
->new (
5030 iterations
=> $iterations,
5034 my $key = $pbkdf2->PBKDF2 ($salt, $word_buf);
5036 my $cipher = Crypt
::CBC
->new ({
5038 cipher
=> "Crypt::Rijndael",
5045 my $encrypted = unpack ("H*", $cipher->encrypt ($data));
5047 $hash_buf = substr ($encrypted, 0, 32);
5049 $tmp_hash = sprintf ("%i:%s:%s%s%s", $iterations, $salt_hex, $prefix, $iv_hex, $hash_buf);
5051 elsif ($mode == 6700)
5053 my $iterations = 64;
5057 $iterations = 1 << int ($iter);
5060 $hash_buf = aix_ssha1_pbkdf2
($word_buf, $salt_buf, $iterations);
5062 $tmp_hash = sprintf ("{ssha1}%02i\$%s\$%s", log ($iterations) / log (2), $salt_buf, $hash_buf);
5064 elsif ($mode == 6800)
5066 my $variant = $additional_param;
5068 if (! defined ($variant))
5070 $variant = int (rand (2));
5073 my $iterations = 500;
5077 $iterations = int ($iter);
5080 my $iv = "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00";
5082 my $hasher = Crypt
::PBKDF2
->hasher_from_algorithm ('HMACSHA2', 256);
5084 my $pbkdf2 = Crypt
::PBKDF2
->new (
5086 iterations
=> $iterations,
5090 my $key = $pbkdf2->PBKDF2 ($salt_buf, $word_buf);
5092 my $cipher = Crypt
::CBC
->new ({
5094 cipher
=> "Crypt::Rijndael",
5103 my $encrypt = $cipher->encrypt (substr ($salt_buf, 0, 16));
5105 $hash_buf = substr (unpack ("H*", $encrypt), 0, 32);
5109 my $verifier = "lastpass rocks\x02\x02";
5111 $hash_buf = unpack ("H*", substr ($cipher->encrypt ($verifier), 0, 16));
5114 $tmp_hash = sprintf ("%s:%i:%s", $hash_buf, $iterations, $salt_buf);
5116 elsif ($mode == 6900)
5118 $hash_buf = gost_hex
($word_buf);
5120 $tmp_hash = sprintf ("%s", $hash_buf);
5122 elsif ($mode == 7100)
5124 my $iterations = 1024;
5128 $iterations = int ($iter);
5131 my $pbkdf2 = Crypt
::PBKDF2
->new
5133 hasher
=> Crypt
::PBKDF2
->hasher_from_algorithm ('HMACSHA2', 512),
5134 iterations
=> $iterations
5137 $hash_buf = unpack ("H*", $pbkdf2->PBKDF2 (pack ("H*", $salt_buf), $word_buf));
5139 $tmp_hash = sprintf ("\$ml\$%i\$%s\$%0128s", $iterations, $salt_buf, $hash_buf);
5141 elsif ($mode == 7200)
5143 my $iterations = 1024;
5147 $iterations = int ($iter);
5150 my $pbkdf2 = Crypt
::PBKDF2
->new (
5151 hasher
=> Crypt
::PBKDF2
->hasher_from_algorithm ('HMACSHA2', 512),
5152 iterations
=> $iterations
5155 $hash_buf = unpack ("H*", $pbkdf2->PBKDF2 (pack ("H*", $salt_buf), $word_buf));
5157 $tmp_hash = sprintf ("grub.pbkdf2.sha512.%i.%s.%0128s", $iterations, $salt_buf, $hash_buf);
5159 elsif ($mode == 7300)
5161 $hash_buf = hmac_hex
($salt_buf, $word_buf, \
&sha1
);
5163 $tmp_hash = sprintf ("%s:%s", unpack ("H*", $salt_buf), $hash_buf);
5165 elsif ($mode == 7400)
5167 my $iterations = 5000;
5169 if (defined ($iter))
5173 $iterations = int ($iter);
5177 $hash_buf = sha256_crypt
($iterations, $word_buf, $salt_buf);
5179 $tmp_hash = sprintf ("%s", $hash_buf);
5181 elsif ($mode == 7500)
5183 my @salt_arr = split ("\\\$", $salt_buf);
5185 my $user = $salt_arr[0];
5187 my $realm = $salt_arr[1];
5189 my $salt = $salt_arr[2];
5191 my $hmac_salt = $salt_arr[3];
5192 my $hmac_salt_bin = pack ("H*", $hmac_salt);
5194 my $clear_data = $salt_arr[4];
5196 my $k = md4
(encode
("UTF-16LE", $word_buf));
5198 my $k1 = hmac_md5
("\x01\x00\x00\x00", $k);
5200 my $k3 = hmac_md5
($hmac_salt_bin, $k1);
5202 if (length ($clear_data) > 1)
5204 my $clear_data_bin = pack ("H*", $clear_data);
5206 $hash_buf = RC4
($k3, $clear_data_bin);
5210 my $hash = $salt_arr[5];
5212 my $hash_bin = pack ("H*", $hash);
5214 my $clear_data = RC4
($k3, $hash_bin);
5216 my $timestamp = substr ($clear_data, 14, 14);
5221 if ($timestamp !~ /^[[:digit:]]{14}$/)
5228 $hash_buf = "\x00" x
36;
5230 if ($hash_buf eq $hash_bin)
5232 $hash_buf = "\x01" x
36;
5237 $hash_buf = $hash_bin;
5241 $tmp_hash = sprintf ("\$krb5pa\$23\$%s\$%s\$%s\$%s%s", $user, $realm, $salt, unpack ("H*", $hash_buf), $hmac_salt);
5243 elsif ($mode == 7600)
5245 $hash_buf = sha1_hex
($salt_buf . sha1_hex
($word_buf));
5247 $tmp_hash = sprintf ("%s:%s", $hash_buf, $salt_buf);
5249 elsif ($mode == 7700)
5251 $word_buf = uc $word_buf;
5252 $salt_buf = uc $salt_buf;
5254 my $word_buf_t = sapb_transcode
($word_buf);
5255 my $salt_buf_t = sapb_transcode
($salt_buf);
5257 my $digest1 = md5
($word_buf_t . $salt_buf_t);
5259 my $data = sapb_waldorf
($digest1, $word_buf_t, $salt_buf_t);
5261 my $digest2 = md5
($data);
5263 my ($a, $b, $c, $d) = unpack ("N4", $digest2);
5268 $tmp_hash = sprintf ("%s\$%08X%08X", $salt_buf, $a, $b);
5270 elsif ($mode == 7800)
5272 my $theMagicArray_s =
5273 "\x91\xac\x51\x14\x9f\x67\x54\x43\x24\xe7\x3b\xe0\x28\x74\x7b\xc2" .
5274 "\x86\x33\x13\xeb\x5a\x4f\xcb\x5c\x08\x0a\x73\x37\x0e\x5d\x1c\x2f" .
5275 "\x33\x8f\xe6\xe5\xf8\x9b\xae\xdd\x16\xf2\x4b\x8d\x2c\xe1\xd4\xdc" .
5276 "\xb0\xcb\xdf\x9d\xd4\x70\x6d\x17\xf9\x4d\x42\x3f\x9b\x1b\x11\x94" .
5277 "\x9f\x5b\xc1\x9b\x06\x05\x9d\x03\x9d\x5e\x13\x8a\x1e\x9a\x6a\xe8" .
5278 "\xd9\x7c\x14\x17\x58\xc7\x2a\xf6\xa1\x99\x63\x0a\xd7\xfd\x70\xc3" .
5279 "\xf6\x5e\x74\x13\x03\xc9\x0b\x04\x26\x98\xf7\x26\x8a\x92\x93\x25" .
5280 "\xb0\xa2\x0d\x23\xed\x63\x79\x6d\x13\x32\xfa\x3c\x35\x02\x9a\xa3" .
5281 "\xb3\xdd\x8e\x0a\x24\xbf\x51\xc3\x7c\xcd\x55\x9f\x37\xaf\x94\x4c" .
5282 "\x29\x08\x52\x82\xb2\x3b\x4e\x37\x9f\x17\x07\x91\x11\x3b\xfd\xcd";
5284 $salt_buf = uc $salt_buf;
5286 my $digest = sha1
($word_buf . $salt_buf);
5288 my ($a, $b, $c, $d, $e) = unpack ("I*", $digest);
5290 my $lengthMagicArray = 0x20;
5291 my $offsetMagicArray = 0;
5293 $lengthMagicArray += (($a >> 0) & 0xff) % 6;
5294 $lengthMagicArray += (($a >> 8) & 0xff) % 6;
5295 $lengthMagicArray += (($a >> 16) & 0xff) % 6;
5296 $lengthMagicArray += (($a >> 24) & 0xff) % 6;
5297 $lengthMagicArray += (($b >> 0) & 0xff) % 6;
5298 $lengthMagicArray += (($b >> 8) & 0xff) % 6;
5299 $lengthMagicArray += (($b >> 16) & 0xff) % 6;
5300 $lengthMagicArray += (($b >> 24) & 0xff) % 6;
5301 $lengthMagicArray += (($c >> 0) & 0xff) % 6;
5302 $lengthMagicArray += (($c >> 8) & 0xff) % 6;
5303 $offsetMagicArray += (($c >> 16) & 0xff) % 8;
5304 $offsetMagicArray += (($c >> 24) & 0xff) % 8;
5305 $offsetMagicArray += (($d >> 0) & 0xff) % 8;
5306 $offsetMagicArray += (($d >> 8) & 0xff) % 8;
5307 $offsetMagicArray += (($d >> 16) & 0xff) % 8;
5308 $offsetMagicArray += (($d >> 24) & 0xff) % 8;
5309 $offsetMagicArray += (($e >> 0) & 0xff) % 8;
5310 $offsetMagicArray += (($e >> 8) & 0xff) % 8;
5311 $offsetMagicArray += (($e >> 16) & 0xff) % 8;
5312 $offsetMagicArray += (($e >> 24) & 0xff) % 8;
5314 my $hash_buf = sha1_hex
($word_buf . substr ($theMagicArray_s, $offsetMagicArray, $lengthMagicArray) . $salt_buf);
5316 $tmp_hash = sprintf ("%s\$%s", $salt_buf, uc $hash_buf);
5318 elsif ($mode == 7900)
5327 my $phpass_it = 1 << $cost;
5329 $hash_buf = sha512
($salt_buf . $word_buf);
5331 for (my $i = 0; $i < $phpass_it; $i++)
5333 $hash_buf = sha512
($hash_buf . $word_buf);
5336 my $base64_buf = substr (Authen
::Passphrase
::PHPass
::_en_base64
($hash_buf), 0, 43);
5338 my $base64_digits = "./0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
5340 my $cost_str = substr ($base64_digits , $cost, 1);
5342 $tmp_hash = sprintf ('$S$%s%s%s', $cost_str, $salt_buf, $base64_buf);
5344 elsif ($mode == 8000)
5346 my $salt_buf_bin = pack ("H*", $salt_buf);
5348 my $word_buf_utf = encode
("UTF-16BE", $word_buf);
5350 $hash_buf = sha256_hex
($word_buf_utf . "\x00" x
(510 - (length ($word_buf) * 2)) . $salt_buf_bin);
5352 $tmp_hash = sprintf ("0xc007%s%s", $salt_buf, $hash_buf);
5354 elsif ($mode == 8100)
5356 $hash_buf = sha1_hex
($salt_buf . $word_buf . "\x00");
5358 $tmp_hash = sprintf ("1%s%s", $salt_buf, $hash_buf);
5360 elsif ($mode == 8200)
5362 my $iterations = 40000;
5364 if (defined ($iter))
5366 $iterations = $iter;
5369 my $salt_hex = substr ($salt_buf, 0, 32);
5370 my $salt = pack ("H*", $salt_hex);
5372 my $data_hex = substr ($salt_buf, 32);
5373 my $data = pack ("H*", $data_hex);
5375 my $pbkdf2 = Crypt
::PBKDF2
->new
5377 hasher
=> Crypt
::PBKDF2
->hasher_from_algorithm ('HMACSHA2', 512),
5378 iterations
=> int $iterations
5381 my $key = $pbkdf2->PBKDF2 ($salt, $word_buf);
5383 $hash_buf = hmac_hex
($data, substr ($key, 32, 32), \
&sha256
, 64);
5385 $tmp_hash = sprintf ("%s:%s:%d:%s", $hash_buf, $salt_hex, $iterations, $data_hex);
5387 elsif ($mode == 8300)
5389 my ($domain, $salt_hex) = split (":", $salt_buf);
5391 my $hashalg = Net
::DNS
::SEC
->digtype ("SHA1");
5393 my $salt = pack ("H*", $salt_hex);
5397 if (defined ($iter))
5399 $iterations = $iter;
5402 my $name = lc ($word_buf . $domain);
5404 my $hash_buf = Net
::DNS
::RR
::NSEC3
::name2hash
($hashalg, $name, $iterations, $salt);
5406 $tmp_hash = sprintf ("%s:%s:%s:%d", $hash_buf, $domain, $salt_hex, $iterations);
5408 elsif ($mode == 8400)
5410 $hash_buf = sha1_hex
($salt_buf . sha1_hex
($salt_buf . sha1_hex
($word_buf)));
5412 $tmp_hash = sprintf ("%s:%s", $hash_buf, $salt_buf);
5414 elsif ($mode == 8500)
5416 $hash_buf = racf_hash
(uc $salt_buf, $word_buf);
5418 $tmp_hash = sprintf ('$racf$*%s*%s', uc $salt_buf, uc $hash_buf);
5420 elsif ($mode == 8600)
5422 my @saved_key = map { ord $_; } split "", $word_buf;
5424 my $len = scalar @saved_key;
5426 my @state = domino_big_md
(\
@saved_key, $len);
5428 $tmp_hash = sprintf ('%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x',
5447 elsif ($mode == 8700)
5449 my $domino_char = undef;
5451 if (defined ($additional_param))
5453 $domino_char = $additional_param;
5456 my @saved_key = map { ord $_; } split "", $word_buf;
5458 my $len = scalar @saved_key;
5460 my @state = domino_big_md
(\
@saved_key, $len);
5462 my $str = "(" . unpack ("H*", join ("", (map { chr $_; } @state))) . ")";
5464 @saved_key = map { ord $_; } split "", $salt_buf . uc $str;
5466 @state = domino_big_md
(\
@saved_key, 34);
5468 $hash_buf = join ("", (map { chr $_; } @state));
5470 $tmp_hash = sprintf ('(G%s)', domino_encode
($salt_buf . $hash_buf, $domino_char));
5472 elsif ($mode == 8900)
5478 if (defined ($additional_param))
5480 $N = $additional_param;
5481 $r = $additional_param2;
5482 $p = $additional_param3;
5485 $hash_buf = scrypt_hash
($word_buf, $salt_buf, $N, $r, $p, 32);
5487 $tmp_hash = sprintf ('%s', $hash_buf);
5489 elsif ($mode == 9100)
5491 my $iterations = 5000;
5493 if (defined ($iter))
5495 $iterations = $iter;
5498 my $domino_char = undef;
5500 # domino 5 hash - SEC_pwddigest_V1 - -m 8600
5502 my @saved_key = map { ord $_; } split "", $word_buf;
5504 my $len = scalar @saved_key;
5506 my @state = domino_big_md
(\
@saved_key, $len);
5509 # domino 6 hash - SEC_pwddigest_V2 - -m 8700
5511 my $salt_part = substr ($salt_buf, 0, 5);
5513 my $str = "(" . unpack ("H*", join ("", (map { chr $_; } @state))) . ")";
5515 @saved_key = map { ord $_; } split "", $salt_part . uc $str;
5517 @state = domino_big_md
(\
@saved_key, 34);
5519 $hash_buf = join ("", (map { chr $_; } @state));
5521 $tmp_hash = sprintf ('(G%s)', domino_encode
($salt_part . $hash_buf, $domino_char));
5524 # domino 8(.5.x) hash - SEC_pwddigest_V3 - -m 9100
5526 my $pbkdf2 = Crypt
::PBKDF2
->new
5528 hash_class
=> 'HMACSHA1',
5529 iterations
=> $iterations,
5536 if (defined ($additional_param))
5538 $chars = $additional_param;
5541 my $digest_new = $pbkdf2->PBKDF2 ($salt_buf, $tmp_hash);
5543 my $iteration_str = "" . $iterations;
5545 for (my $i = length ($iterations); $i < 10; $i++)
5547 $iterations = "0" . $iterations;
5550 $tmp_hash = sprintf ('(H%s)', domino_85x_encode
($salt_buf . $iterations . $chars . $digest_new, $domino_char));
5552 elsif ($mode == 9200)
5554 my $iterations = 20000;
5556 my $pbkdf2 = Crypt
::PBKDF2
->new
5558 hasher
=> Crypt
::PBKDF2
->hasher_from_algorithm ('HMACSHA2', 256),
5559 iterations
=> $iterations
5562 $hash_buf = encode_base64
($pbkdf2->PBKDF2 ($salt_buf, $word_buf));
5566 for (my $i = 0; $i < 43; $i++)
5568 $tmp_hash .= $CISCO_BASE64_MAPPING->{substr ($hash_buf, $i, 1)};
5571 $tmp_hash = sprintf ("\$8\$%s\$%s", $salt_buf, $tmp_hash);
5573 elsif ($mode == 9300)
5579 $hash_buf = scrypt_b64
($word_buf, $salt_buf, $N, $r, $p, 32);
5583 for (my $i = 0; $i < 43; $i++)
5585 $tmp_hash .= $CISCO_BASE64_MAPPING->{substr ($hash_buf, $i, 1)};
5588 $tmp_hash = sprintf ('$9$%s$%s', $salt_buf, $tmp_hash);
5590 elsif ($mode == 9400)
5592 my $iterations = 50000;
5596 $iterations = int ($iter);
5599 my $aes_key_size = 128; # or 256
5601 if (defined ($additional_param2))
5603 $aes_key_size = $additional_param2;
5606 $salt_buf = pack ("H*", $salt_buf);
5608 my $tmp = sha1
($salt_buf . encode
("UTF-16LE", $word_buf));
5610 for (my $i = 0; $i < $iterations; $i++)
5612 my $num32 = pack ("L", $i);
5614 $tmp = sha1
($num32 . $tmp);
5617 my $zero32 = pack ("L", 0x00);
5619 my $derivation_array1 = pack ("C", 0x36) x
64;
5620 my $derivation_array2 = pack ("C", 0x5C) x
64;
5622 $tmp = sha1
($tmp . $zero32);
5624 my $tmp2 = sha1
($derivation_array1 ^ $tmp);
5625 my $tmp3 = sha1
($derivation_array2 ^ $tmp);
5627 my $key = substr ($tmp2 . $tmp3, 0, $aes_key_size / 8);
5629 my $m = Crypt
::Mode
::ECB
->new ('AES', 0);
5633 if (defined $additional_param)
5635 $encdata = $m->decrypt (pack ("H*", $additional_param), $key);
5639 $encdata = "A" x
16; ## can be anything
5642 my $data1_buf = $encdata;
5643 my $data2_buf = sha1
(substr ($data1_buf, 0, 16));
5645 $data1_buf = substr ($data1_buf . ("\x00" x
16), 0, 16);
5646 $data2_buf = substr ($data2_buf . ("\x00" x
16), 0, 32);
5648 my $encrypted1 = unpack ("H*", $m->encrypt ($data1_buf, $key));
5649 my $encrypted2 = unpack ("H*", $m->encrypt ($data2_buf, $key));
5651 $encrypted1 = substr ($encrypted1, 0, 32);
5652 $encrypted2 = substr ($encrypted2, 0, 40);
5654 $tmp_hash = sprintf ("\$office\$*%d*%d*%d*%d*%s*%s*%s", 2007, 20, $aes_key_size, 16, unpack ("H*", $salt_buf), $encrypted1, $encrypted2);
5656 elsif ($mode == 9500)
5658 my $iterations = 100000;
5662 $iterations = int ($iter);
5665 $salt_buf = pack ("H*", $salt_buf);
5667 my $tmp = sha1
($salt_buf . encode
("UTF-16LE", $word_buf));
5669 for (my $i = 0; $i < $iterations; $i++)
5671 my $num32 = pack ("L", $i);
5673 $tmp = sha1
($num32 . $tmp);
5676 my $encryptedVerifierHashInputBlockKey = "\xfe\xa7\xd2\x76\x3b\x4b\x9e\x79";
5677 my $encryptedVerifierHashValueBlockKey = "\xd7\xaa\x0f\x6d\x30\x61\x34\x4e";
5679 my $final1 = sha1
($tmp . $encryptedVerifierHashInputBlockKey);
5680 my $final2 = sha1
($tmp . $encryptedVerifierHashValueBlockKey);
5682 my $key1 = substr ($final1, 0, 16);
5683 my $key2 = substr ($final2, 0, 16);
5685 my $cipher1 = Crypt
::CBC
->new ({
5687 cipher
=> "Crypt::Rijndael",
5695 my $cipher2 = Crypt
::CBC
->new ({
5697 cipher
=> "Crypt::Rijndael",
5707 if (defined $additional_param)
5709 $encdata = $cipher1->decrypt (pack ("H*", $additional_param));
5713 $encdata = "A" x
16; ## can be anything
5716 my $data1_buf = $encdata;
5717 my $data2_buf = sha1
(substr ($data1_buf, 0, 16));
5719 my $encrypted1 = unpack ("H*", $cipher1->encrypt ($data1_buf));
5720 my $encrypted2 = unpack ("H*", $cipher2->encrypt ($data2_buf));
5722 $encrypted2 = substr ($encrypted2, 0, 64);
5724 $tmp_hash = sprintf ("\$office\$*%d*%d*%d*%d*%s*%s*%s", 2010, 100000, 128, 16, unpack ("H*", $salt_buf), $encrypted1, $encrypted2);
5726 elsif ($mode == 9600)
5728 my $iterations = 100000;
5732 $iterations = int ($iter);
5735 $salt_buf = pack ("H*", $salt_buf);
5737 my $tmp = sha512
($salt_buf . encode
("UTF-16LE", $word_buf));
5739 for (my $i = 0; $i < $iterations; $i++)
5741 my $num32 = pack ("L", $i);
5743 $tmp = sha512
($num32 . $tmp);
5746 my $encryptedVerifierHashInputBlockKey = "\xfe\xa7\xd2\x76\x3b\x4b\x9e\x79";
5747 my $encryptedVerifierHashValueBlockKey = "\xd7\xaa\x0f\x6d\x30\x61\x34\x4e";
5749 my $final1 = sha512
($tmp . $encryptedVerifierHashInputBlockKey);
5750 my $final2 = sha512
($tmp . $encryptedVerifierHashValueBlockKey);
5752 my $key1 = substr ($final1, 0, 32);
5753 my $key2 = substr ($final2, 0, 32);
5755 my $cipher1 = Crypt
::CBC
->new ({
5757 cipher
=> "Crypt::Rijndael",
5765 my $cipher2 = Crypt
::CBC
->new ({
5767 cipher
=> "Crypt::Rijndael",
5777 if (defined $additional_param)
5779 $encdata = $cipher1->decrypt (pack ("H*", $additional_param));
5783 $encdata = "A" x
16; ## can be anything
5786 my $data1_buf = $encdata;
5787 my $data2_buf = sha512
(substr ($data1_buf, 0, 16));
5789 my $encrypted1 = unpack ("H*", $cipher1->encrypt ($data1_buf));
5790 my $encrypted2 = unpack ("H*", $cipher2->encrypt ($data2_buf));
5792 $encrypted2 = substr ($encrypted2, 0, 64);
5794 $tmp_hash = sprintf ("\$office\$*%d*%d*%d*%d*%s*%s*%s", 2013, 100000, 256, 16, unpack ("H*", $salt_buf), $encrypted1, $encrypted2);
5796 elsif ($mode == 9700)
5798 $salt_buf = pack ("H*", $salt_buf);
5800 my $tmp = md5
(encode
("UTF-16LE", $word_buf));
5802 $tmp = substr ($tmp, 0, 5);
5806 for (my $i = 0; $i < 16; $i++)
5814 $tmp = substr ($tmp, 0, 5);
5818 if (defined $additional_param2)
5820 $version = $additional_param2;
5824 $version = (unpack ("L", $tmp) & 1) ?
0 : 1;
5827 my $rc4_key = md5
($tmp . "\x00\x00\x00\x00");
5829 my $m = Crypt
::RC4
->new (substr ($rc4_key, 0, 16));
5833 if (defined $additional_param)
5835 $encdata = $m->RC4 (pack ("H*", $additional_param));
5839 $encdata = "A" x
16; ## can be anything
5842 my $data1_buf = $encdata;
5843 my $data2_buf = md5
(substr ($data1_buf, 0, 16));
5845 $m = Crypt
::RC4
->new (substr ($rc4_key, 0, 16));
5847 my $encrypted1 = $m->RC4 ($data1_buf);
5848 my $encrypted2 = $m->RC4 ($data2_buf);
5850 $tmp_hash = sprintf ("\$oldoffice\$%d*%s*%s*%s", $version, unpack ("H*", $salt_buf), unpack ("H*", $encrypted1), unpack ("H*", $encrypted2));
5852 elsif ($mode == 9800)
5854 $salt_buf = pack ("H*", $salt_buf);
5856 my $tmp = sha1
($salt_buf. encode
("UTF-16LE", $word_buf));
5860 if (defined $additional_param2)
5862 $version = $additional_param2;
5866 $version = (unpack ("L", $tmp) & 1) ?
3 : 4;
5869 my $rc4_key = sha1
($tmp . "\x00\x00\x00\x00");
5873 $rc4_key = substr ($rc4_key, 0, 5) . "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00";
5876 my $m = Crypt
::RC4
->new (substr ($rc4_key, 0, 16));
5880 if (defined $additional_param)
5882 $encdata = $m->RC4 (pack ("H*", $additional_param));
5886 $encdata = "A" x
16; ## can be anything
5889 my $data1_buf = $encdata;
5890 my $data2_buf = sha1
(substr ($data1_buf, 0, 16));
5892 $m = Crypt
::RC4
->new (substr ($rc4_key, 0, 16));
5894 my $encrypted1 = $m->RC4 ($data1_buf);
5895 my $encrypted2 = $m->RC4 ($data2_buf);
5897 $tmp_hash = sprintf ("\$oldoffice\$%d*%s*%s*%s", $version, unpack ("H*", $salt_buf), unpack ("H*", $encrypted1), unpack ("H*", $encrypted2));
5899 elsif ($mode == 9900)
5901 $tmp_hash = sprintf ("%s", md5_hex
($word_buf . "\0" x
(100 - length ($word_buf))));
5903 elsif ($mode == 10000)
5905 my $iterations = 10000;
5909 $iterations = int ($iter);
5912 my $pbkdf2 = Crypt
::PBKDF2
->new
5914 hasher
=> Crypt
::PBKDF2
->hasher_from_algorithm ('HMACSHA2', 256),
5915 iterations
=> $iterations
5918 $hash_buf = encode_base64
($pbkdf2->PBKDF2 ($salt_buf, $word_buf));
5919 $hash_buf =~ s/[\r\n]//g;
5921 $tmp_hash = sprintf ("pbkdf2_sha256\$%i\$%s\$%s", $iterations, $salt_buf, $hash_buf);
5923 elsif ($mode == 10100)
5925 my $seed = pack ("H*", $salt_buf);
5927 my ($hi, $lo) = siphash
($word_buf, $seed);
5929 my $hi_s = sprintf ("%08x", $hi);
5930 my $lo_s = sprintf ("%08x", $lo);
5932 $hi_s =~ s/^(..)(..)(..)(..)$/$4$3$2$1/;
5933 $lo_s =~ s/^(..)(..)(..)(..)$/$4$3$2$1/;
5935 $tmp_hash = sprintf ("%s%s:2:4:%s", $hi_s, $lo_s, $salt_buf);
5937 elsif ($mode == 10200)
5939 my $challengeb64 = encode_base64
($salt_buf);
5940 $challengeb64 =~ s/[\r\n]//g;
5944 if (defined $additional_param)
5946 $username = $additional_param;
5953 $hash_buf = hmac_hex
($salt_buf, $word_buf, \
&md5
);
5955 my $responseb64 = encode_base64
($username . " " . $hash_buf);
5956 $responseb64 =~ s/[\r\n]//g;
5958 $tmp_hash = sprintf ('$cram_md5$%s$%s', $challengeb64, $responseb64);
5960 elsif ($mode == 10300)
5962 my $iterations = 1024;
5966 $iterations = int ($iter);
5969 my $hash_buf = $salt_buf;
5971 for (my $pos = 0; $pos < $iterations; $pos++)
5973 $hash_buf = sha1
($word_buf . $hash_buf);
5976 $hash_buf = encode_base64
($hash_buf . $salt_buf);
5977 $hash_buf =~ s/[\r\n]//g;
5979 $tmp_hash = sprintf ("{x-issha, %i}%s", $iterations, $hash_buf);
5981 elsif ($mode == 10400)
5984 my $u = $additional_param;
5985 my $o = $additional_param2;
5986 my $P = $additional_param3;
5988 if (defined $u == 0)
5993 if (defined $o == 0)
5998 if (defined $P == 0)
6005 for (my $i = 0; $i < 32; $i++)
6007 $padding .= pack ("C", $pdf_padding[$i]);
6010 my $res = pdf_compute_encryption_key
($word_buf, $padding, $id, $u, $o, $P, 1, 2, 0);
6012 my $m = Crypt
::RC4
->new (substr ($res, 0, 5));
6014 $u = $m->RC4 ($padding);
6016 $tmp_hash = sprintf ('$pdf$%d*%d*40*%d*%d*16*%s*32*%s*32*%s', 1, 2, $P, 0, $id, unpack ("H*", $u), $o);
6018 elsif ($mode == 10500)
6021 my $u = $additional_param;
6022 my $o = $additional_param2;
6023 my $P = $additional_param3;
6024 my $V = $additional_param4;
6025 my $R = $additional_param5;
6026 my $enc = $additional_param6;
6028 if (defined $u == 0)
6035 if (defined $o == 0)
6040 if (defined $R == 0)
6042 $R = get_random_num
(3, 5);
6045 if (defined $V == 0)
6047 $V = ($R == 3) ?
2 : 4;
6050 if (defined $P == 0)
6052 $P = ($R == 3) ?
-4 : -1028;
6055 if (defined $enc == 0)
6057 $enc = ($R == 3) ?
1 : get_random_num
(0, 2);
6062 for (my $i = 0; $i < 32; $i++)
6064 $padding .= pack ("C", $pdf_padding[$i]);
6067 my $res = pdf_compute_encryption_key
($word_buf, $padding, $id, $u, $o, $P, $V, $R, $enc);
6069 my $digest = md5
($padding . pack ("H*", $id));
6071 my $m = Crypt
::RC4
->new ($res);
6073 $u = $m->RC4 ($digest);
6075 my @ress = split "", $res;
6077 for (my $x = 1; $x <= 19; $x++)
6081 for (my $i = 0; $i < 16; $i++)
6083 $xor[$i] = chr (ord ($ress[$i]) ^ $x);
6086 my $s = join ("", @xor);
6088 my $m2 = Crypt
::RC4
->new ($s);
6093 $u .= substr (pack ("H*", $u_save), 16, 16);
6095 $tmp_hash = sprintf ('$pdf$%d*%d*128*%d*%d*16*%s*32*%s*32*%s', $V, $R, $P, $enc, $id, unpack ("H*", $u), $o);
6097 elsif ($mode == 10600)
6100 my $rest = $additional_param;
6102 if (defined $id == 0)
6107 if (defined $rest == 0)
6113 $rest .= "*127*00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000*32*0000000000000000000000000000000000000000000000000000000000000000*32*0000000000000000000000000000000000000000000000000000000000000000";
6116 my @data = split /\*/, $rest;
6118 my $u = pack ("H*", $data[1]);
6120 my $h = sha256
($word_buf . substr ($u, 32, 8));
6122 $data[1] = unpack ("H*", $h . substr ($u, 32));
6124 $rest = join ("*", @data);
6126 $tmp_hash = sprintf ('$pdf$5*5*256*-1028*1*16*%s*%s', $id, $rest);
6128 elsif ($mode == 10700)
6131 my $rest = $additional_param;
6133 if (defined $id == 0)
6138 if (defined $rest == 0)
6144 $rest .= "*127*00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000*32*0000000000000000000000000000000000000000000000000000000000000000*32*0000000000000000000000000000000000000000000000000000000000000000";
6147 my @datax = split /\*/, $rest;
6149 my $u = pack ("H*", $datax[1]);
6151 my $block = sha256
($word_buf . substr ($u, 32, 8));
6153 my $block_size = 32;
6155 my $data = 0x00 x
64;
6161 for (my $i = 0; $i < 64 || $i < $data63 + 32; $i++)
6163 $data = $word_buf . $block;
6165 $data_len = length ($data);
6167 for (my $k = 1; $k < 64; $k++)
6169 $data .= $word_buf . $block;
6172 my $aes = Crypt
::CBC
->new ({
6173 key
=> substr ($block, 0, 16),
6174 cipher
=> "Crypt::Rijndael",
6175 iv
=> substr ($block, 16, 16),
6182 my $data = $aes->encrypt ($data);
6186 for (my $j = 0; $j < 16; $j++)
6188 $sum += ord (substr ($data, $j, 1));
6191 $block_size = 32 + ($sum % 3) * 16;
6193 if ($block_size == 32)
6195 $block = sha256
(substr ($data, 0, $data_len * 64));
6197 elsif ($block_size == 48)
6199 $block = sha384
(substr ($data, 0, $data_len * 64));
6201 elsif ($block_size == 64)
6203 $block = sha512
(substr ($data, 0, $data_len * 64));
6206 $data63 = ord (substr ($data, $data_len * 64 - 1, 1));
6209 $datax[1] = unpack ("H*", substr ($block, 0, 32) . substr ($u, 32));
6211 $rest = join ("*", @datax);
6213 $tmp_hash = sprintf ('$pdf$5*6*256*-1028*1*16*%s*%s', $id, $rest);
6215 elsif ($mode == 10800)
6217 $hash_buf = sha384_hex
($word_buf);
6219 $tmp_hash = sprintf ("%s", $hash_buf);
6221 elsif ($mode == 10900)
6223 my $iterations = 1000;
6227 $iterations = int ($iter);
6232 if (defined $additional_param)
6234 $out_len = $additional_param;
6237 my $pbkdf2 = Crypt
::PBKDF2
->new
6239 hasher
=> Crypt
::PBKDF2
->hasher_from_algorithm ('HMACSHA2', 256),
6240 iterations
=> $iterations,
6241 output_len
=> $out_len
6244 $hash_buf = encode_base64
($pbkdf2->PBKDF2 ($salt_buf, $word_buf));
6245 $hash_buf =~ s/[\r\n]//g;
6247 my $base64_salt_buf = encode_base64
($salt_buf);
6249 chomp ($base64_salt_buf);
6251 $tmp_hash = sprintf ("sha256:%i:%s:%s", $iterations, $base64_salt_buf, $hash_buf);
6253 elsif ($mode == 11000)
6255 $hash_buf = md5_hex
($salt_buf . $word_buf);
6257 $tmp_hash = sprintf ("%s:%s", $hash_buf, $salt_buf);
6259 elsif ($mode == 11100)
6261 my $user = "postgres";
6263 if (defined $additional_param)
6265 $user = $additional_param;
6268 $hash_buf = md5_hex
(md5_hex
($word_buf . $user) . pack ("H*", $salt_buf));
6270 $tmp_hash = sprintf ("\$postgres\$%s*%s*%s", $user, $salt_buf, $hash_buf);
6272 elsif ($mode == 11200)
6274 my $sha1_pass = sha1
($word_buf);
6275 my $double_sha1 = sha1
($sha1_pass);
6277 my $xor_part1 = $sha1_pass;
6278 my $xor_part2 = sha1
(pack ("H*", $salt_buf) . $double_sha1);
6282 for (my $i = 0; $i < 20; $i++)
6284 my $first_byte = substr ($xor_part1, $i, 1);
6285 my $second_byte = substr ($xor_part2, $i, 1);
6287 my $xor_result = $first_byte ^ $second_byte;
6289 $hash_buf .= unpack ("H*", $xor_result);
6292 $tmp_hash = sprintf ("\$mysqlna\$%s*%s", $salt_buf, $hash_buf);
6294 elsif ($mode == 11300)
6296 my $ckey_buf = get_random_string
(96);
6298 if (length ($additional_param))
6300 $ckey_buf = $additional_param;
6303 my $public_key_buf = get_random_string
(66);
6305 if (length ($additional_param2))
6307 $public_key_buf = $additional_param2;
6310 my $salt_iter = get_random_num
(150000, 250000);
6314 $salt_iter = int ($iter);
6317 my $hash_buf = sha512
($word_buf . pack ("H*", $salt_buf));
6319 for (my $i = 1; $i < $salt_iter; $i++)
6321 $hash_buf = sha512
($hash_buf);
6324 my $data = get_random_string
(32);
6326 my $aes = Crypt
::CBC
->new ({
6327 key
=> substr ($hash_buf, 0, 32),
6328 cipher
=> "Crypt::Rijndael",
6329 iv
=> substr ($hash_buf, 32, 16),
6333 padding
=> "standard",
6336 my $cry_master_buf = (unpack ("H*", $aes->encrypt ($data)));
6338 $tmp_hash = sprintf ('$bitcoin$%d$%s$%d$%s$%d$%d$%s$%d$%s',
6339 length ($cry_master_buf),
6346 length ($public_key_buf),
6349 elsif ($mode == 11400)
6351 my ($directive, $URI_server, $URI_client, $user, $realm, $nonce, $nonce_count, $nonce_client, $qop, $method, $URI, $URI_prefix, $URI_resource, $URI_suffix);
6353 $directive = "MD5"; # only directive currently supported
6355 if (defined ($additional_param))
6357 $user = $additional_param;
6358 $realm = $additional_param2;
6360 $nonce_count = $additional_param3;
6361 $nonce_client = $additional_param4;
6362 $qop = $additional_param5;
6363 $method = $additional_param6;
6365 $URI_prefix = $additional_param7;
6366 $URI_resource = $additional_param8;
6367 $URI_suffix = $additional_param9;
6369 # not needed information
6371 $URI_server = $additional_param10;
6372 $URI_client = $additional_param11;
6376 $user = get_random_string
(get_random_num
(0, 12 + 1));
6378 # special limit: (user_len + 1 + realm_len + 1 + word_buf_len) < 56
6379 my $realm_max_len = 55 - length ($user) - 1 - length ($word_buf) - 1;
6381 if ($realm_max_len < 1) # should never happen
6386 $realm_max_len = min
(20, $realm_max_len);
6388 $realm = get_random_string
(get_random_num
(0, $realm_max_len + 1));
6392 if (get_random_num
(0, 1 + 1) == 1)
6396 $nonce_count = get_random_string
(get_random_num
(0, 10 + 1));
6397 $nonce_client = get_random_string
(get_random_num
(0, 12 + 1));
6407 $method = get_random_string
(get_random_num
(0, 24 + 1));
6409 $URI_prefix = get_random_string
(get_random_num
(0, 10 + 1));
6410 $URI_resource = get_random_string
(get_random_num
(1, 32 + 1));
6411 $URI_suffix = get_random_string
(get_random_num
(0, 32 + 1));
6413 # not needed information
6415 $URI_server = get_random_string
(get_random_num
(0, 32 + 1));
6416 $URI_client = $URI_resource; # simplification
6423 if (length ($URI_prefix) > 0)
6425 $URI = $URI_prefix . ":";
6428 $URI .= $URI_resource;
6430 if (length ($URI_suffix) > 0)
6432 $URI .= ":" . $URI_suffix;
6435 my $HA2 = md5_hex
($method . ":" . $URI);
6437 my $HA1 = md5_hex
($user . ":" . $realm . ":" . $word_buf);
6441 if (($qop eq "auth") || ($qop eq "auth-int"))
6443 $tmp_buf = $nonce . ":" . $nonce_count . ":" . $nonce_client . ":" . $qop;
6450 my $hash_buf = md5_hex
($HA1 . ":" . $tmp_buf . ":" . $HA2);
6452 $tmp_hash = sprintf ("\$sip\$*%s*%s*%s*%s*%s*%s*%s*%s*%s*%s*%s*%s*%s*%s", $URI_server, $URI_resource, $user, $realm, $method, $URI_prefix, $URI_resource, $URI_suffix, $nonce, $nonce_client, $nonce_count, $qop, $directive, $hash_buf);
6454 elsif ($mode == 11500)
6456 $hash_buf = crc32
($word_buf);
6458 $tmp_hash = sprintf ("%08x:00000000", $hash_buf);
6460 elsif ($mode == 11600)
6462 my ($p, $num_cycle_power, $seven_zip_salt_len, $seven_zip_salt_buf, $salt_len, $data_len, $unpack_size, $data_buf);
6466 my $validation_only = 0;
6468 $validation_only = 1 if (defined ($additional_param));
6470 if ($validation_only == 1)
6472 $num_cycle_power = int ($iter);
6473 $seven_zip_salt_len = $additional_param;
6474 $seven_zip_salt_buf = $additional_param2;
6475 $salt_len = $additional_param3;
6476 # $salt_buf set in parser
6477 # $hash_buf (resulting crc)
6478 $data_len = $additional_param4;
6479 $unpack_size = $additional_param5;
6480 $data_buf = $additional_param6;
6484 $num_cycle_power = 14; # by default it is 19
6485 $seven_zip_salt_len = 0;
6486 $seven_zip_salt_buf = "";
6487 $salt_len = length ($salt_buf);
6488 # $salt_buf set automatically
6489 # $hash_buf (resulting crc)
6490 # $data_len will be set when encrypting
6491 $unpack_size = get_random_num
(1, 32 + 1);
6492 $data_buf = get_random_string
($unpack_size);
6496 # 2 ^ NumCyclesPower "iterations" of SHA256 (only one final SHA256)
6499 $word_buf = encode
("UTF-16LE", $word_buf);
6501 my $rounds = 1 << $num_cycle_power;
6505 for (my $i = 0; $i < $rounds; $i++)
6509 $num_buf .= pack ("V", $i);
6510 $num_buf .= "\x00" x
4;
6512 # this would be better but only works on 64-bit systems:
6513 # $num_buf = pack ("q", $i);
6515 $pass_buf .= sprintf ("%s%s", $word_buf, $num_buf);
6518 my $key = sha256
($pass_buf);
6520 # the salt_buf is our IV for AES CBC
6523 my $salt_buf_len = length ($salt_buf);
6524 my $salt_padding_len = 0;
6526 if ($salt_buf_len < 16)
6528 $salt_padding_len = 16 - $salt_buf_len;
6531 $salt_buf .= "\x00" x
$salt_padding_len;
6533 my $aes = Crypt
::CBC
->new ({
6534 cipher
=> "Crypt::Rijndael",
6542 if ($validation_only == 1)
6546 my $decrypted_data = $aes->decrypt ($data_buf);
6548 $decrypted_data = substr ($decrypted_data, 0, $unpack_size);
6550 $hash_buf = crc32
($decrypted_data);
6556 $hash_buf = crc32
($data_buf);
6558 $data_buf = $aes->encrypt ($data_buf);
6560 $data_len = length ($data_buf);
6563 $tmp_hash = sprintf ("\$7z\$%i\$%i\$%i\$%s\$%i\$%08s\$%u\$%u\$%u\$%s", $p, $num_cycle_power, $seven_zip_salt_len, $seven_zip_salt_buf, $salt_len, unpack ("H*", $salt_buf), $hash_buf, $data_len, $unpack_size, unpack ("H*", $data_buf));
6565 elsif ($mode == 11900)
6567 my $iterations = 1000;
6571 $iterations = int ($iter);
6576 if (defined $additional_param)
6578 $out_len = $additional_param;
6582 # call PHP here - WTF
6585 # sanitize $word_buf and $salt_buf:
6587 my $word_buf_base64 = encode_base64
($word_buf);
6588 $word_buf_base64 =~ s/[\r\n]//g;
6590 my $salt_buf_base64 = encode_base64
($salt_buf);
6591 $salt_buf_base64 =~ s/[\r\n]//g;
6595 $out_len = int ($out_len);
6597 # output is in hex encoding, otherwise it could be screwed (but shouldn't)
6599 my $php_code = <<'END_CODE';
6601 function pbkdf2 ($algorithm, $password, $salt, $count, $key_length, $raw_output = false)
6603 $algorithm = strtolower ($algorithm);
6605 if (! in_array ($algorithm, hash_algos (), true))
6607 trigger_error ("PBKDF2 ERROR: Invalid hash algorithm.", E_USER_ERROR);
6610 if ($count <= 0 || $key_length <= 0)
6612 trigger_error ("PBKDF2 ERROR: Invalid parameters.", E_USER_ERROR);
6615 if (function_exists ("hash_pbkdf2"))
6619 $key_length = $key_length * 2;
6622 return hash_pbkdf2 ($algorithm, $password, $salt, $count, $key_length, $raw_output);
6625 $hash_length = strlen (hash ($algorithm, "", true));
6626 $block_count = ceil ($key_length / $hash_length);
6630 for ($i = 1; $i <= $block_count; $i++)
6632 $last = $salt . pack ("N", $i);
6634 $last = $xorsum = hash_hmac ($algorithm, $last, $password, true);
6636 for ($j = 1; $j < $count; $j++)
6638 $xorsum ^= ($last = hash_hmac ($algorithm, $last, $password, true));
6646 return substr ($output, 0, $key_length);
6650 return bin2hex (substr ($output, 0, $key_length));
6654 print pbkdf2 ("md5", base64_decode ("$word_buf_base64"), base64_decode ("$salt_buf_base64"), $iterations, $out_len, False);
6658 # replace with these command line arguments
6660 $php_code =~ s/\$word_buf_base64/$word_buf_base64/;
6661 $php_code =~ s/\$salt_buf_base64/$salt_buf_base64/;
6662 $php_code =~ s/\$iterations/$iterations/;
6663 $php_code =~ s/\$out_len/$out_len/;
6665 my $php_output = `php -r '$php_code'`;
6667 $hash_buf = pack ("H*", $php_output);
6669 $hash_buf = encode_base64 ($hash_buf);
6670 $hash_buf =~ s/[\r\n]//g;
6672 my $base64_salt_buf = encode_base64 ($salt_buf);
6674 chomp ($base64_salt_buf);
6676 $tmp_hash = sprintf ("md5:%i:%s:%s", $iterations, $base64_salt_buf, $hash_buf);
6678 elsif ($mode == 12000)
6680 my $iterations = 1000;
6684 $iterations = int ($iter);
6689 if (defined $additional_param)
6691 $out_len = $additional_param;
6694 my $pbkdf2 = Crypt::PBKDF2->new
6696 hasher => Crypt::PBKDF2->hasher_from_algorithm ('HMACSHA1'),
6697 iterations => $iterations,
6698 output_len => $out_len
6701 $hash_buf = encode_base64 ($pbkdf2->PBKDF2 ($salt_buf, $word_buf));
6702 $hash_buf =~ s/[\r\n]//g;
6704 my $base64_salt_buf = encode_base64 ($salt_buf);
6706 chomp ($base64_salt_buf);
6708 $tmp_hash = sprintf ("sha1:%i:%s:%s", $iterations, $base64_salt_buf, $hash_buf);
6710 elsif ($mode == 12100)
6712 my $iterations = 1000;
6716 $iterations = int ($iter);
6721 if (defined $additional_param)
6723 $out_len = $additional_param;
6726 my $pbkdf2 = Crypt::PBKDF2->new
6728 hasher => Crypt::PBKDF2->hasher_from_algorithm ('HMACSHA2', 512),
6729 iterations => $iterations,
6730 output_len => $out_len
6733 $hash_buf = encode_base64 ($pbkdf2->PBKDF2 ($salt_buf, $word_buf));
6734 $hash_buf =~ s/[\r\n]//g;
6736 my $base64_salt_buf = encode_base64 ($salt_buf);
6738 chomp ($base64_salt_buf);
6740 $tmp_hash = sprintf ("sha512:%i:%s:%s", $iterations, $base64_salt_buf, $hash_buf);
6742 elsif ($mode == 12200)
6744 my $iterations = 65536;
6746 my $default_salt = 0;
6748 if (defined $additional_param)
6750 $default_salt = int ($additional_param);
6753 if ($default_salt == 1)
6755 $salt_buf = "0011223344556677";
6758 $hash_buf = sha512 (pack ("H*", $salt_buf) . $word_buf);
6760 for (my $i = 0; $i < $iterations; $i++)
6762 $hash_buf = sha512 ($hash_buf);
6765 $hash_buf = unpack ("H*", $hash_buf);
6766 $hash_buf = substr ($hash_buf, 0, 16);
6768 if ($default_salt == 0)
6770 $tmp_hash = sprintf ("\$ecryptfs\$0\$1\$%s\$%s", $salt_buf, $hash_buf);
6774 $tmp_hash = sprintf ("\$ecryptfs\$0\$%s", $hash_buf);
6777 elsif ($mode == 12300)
6779 my $iterations = 4096;
6781 my $hasher = Crypt::PBKDF2->hasher_from_algorithm ('HMACSHA2', 512);
6783 my $pbkdf2 = Crypt::PBKDF2->new (
6785 iterations => $iterations,
6789 my $salt_bin = pack ("H*", $salt_buf);
6791 my $key = $pbkdf2->PBKDF2 ($salt_bin. "AUTH_PBKDF2_SPEEDY_KEY", $word_buf);
6793 $hash_buf = sha512_hex ($key . $salt_bin);
6795 $tmp_hash = sprintf ("%s%s", uc ($hash_buf), uc ($salt_buf));
6797 elsif ($mode == 12400)
6803 $iterations = int ($iter);
6807 $iterations = get_random_num (1, 5001 + 1);
6810 my $key_value = fold_password ($word_buf);
6812 my $data = "\x00\x00\x00\x00\x00\x00\x00\x00";
6813 my $salt_value = base64_to_int24 ($salt_buf);
6815 $hash_buf = crypt_rounds ($key_value, $iterations, $salt_value, $data);
6817 $tmp_hash = sprintf ("_%s%s%s", int24_to_base64 ($iterations), $salt_buf, block_to_base64 ($hash_buf));
6819 elsif ($mode == 12600)
6821 $hash_buf = sha1_hex ($word_buf);
6823 $hash_buf = sha256_hex ($salt_buf . uc $hash_buf);
6825 $tmp_hash = sprintf ("%s:%s", $hash_buf, $salt_buf);
6827 elsif ($mode == 12700)
6829 my $iterations = 10;
6832 "guid" : "00000000-0000-0000-0000-000000000000",
6833 "sharedKey" : "00000000-0000-0000-0000-000000000000",
6834 "options" : {"pbkdf2_iterations":10,"fee_policy":0,"html5_notifications":false,"logout_time":600000,"tx_display":0,"always_keep_local_backup":false}|;
6836 my $salt_buf_bin = pack ("H*", $salt_buf);
6838 my $hasher = Crypt::PBKDF2->hasher_from_algorithm ('HMACSHA1');
6840 my $pbkdf2 = Crypt::PBKDF2->new (
6842 iterations => $iterations,
6846 my $key = $pbkdf2->PBKDF2 ($salt_buf_bin, $word_buf);
6848 my $cipher = Crypt::CBC->new ({
6850 cipher => "Crypt::Rijndael",
6851 iv => $salt_buf_bin,
6857 my $encrypted = unpack ("H*", $cipher->encrypt ($data));
6859 $tmp_hash = sprintf ("\$blockchain\$%s\$%s", length ($salt_buf . $encrypted) / 2, $salt_buf . $encrypted);
6861 elsif ($mode == 12800)
6863 my $iterations = 100;
6867 $iterations = int ($iter);
6870 my $nt = md4_hex (encode ("UTF-16LE", $word_buf));
6872 my $pbkdf2 = Crypt::PBKDF2->new
6874 hasher => Crypt::PBKDF2->hasher_from_algorithm ('HMACSHA2', 256),
6875 iterations => $iterations,
6879 my $salt_buf_bin = pack ("H*", $salt_buf);
6881 my $hash = $pbkdf2->PBKDF2 ($salt_buf_bin, uc (encode ("UTF-16LE", $nt)));
6883 $tmp_hash = sprintf ("v1;PPH1_MD4,%s,%d,%s", $salt_buf, $iterations, unpack ("H*", $hash));
6885 elsif ($mode == 12900)
6887 my $iterations = 4096;
6891 $iterations = int ($iter);
6894 my $salt2 = $salt_buf . $salt_buf;
6896 if (defined $additional_param)
6898 $salt2 = $additional_param;
6901 my $pbkdf2 = Crypt::PBKDF2->new
6903 hasher => Crypt::PBKDF2->hasher_from_algorithm ('HMACSHA2', 256),
6904 iterations => $iterations,
6908 my $salt_buf_bin = pack ("H*", $salt_buf);
6910 my $hash = $pbkdf2->PBKDF2 ($salt_buf_bin, $word_buf);
6912 my $salt2_bin = pack ("H*", $salt2);
6914 my $hash_hmac = hmac_hex ($salt2_bin, $hash, \&sha256, 64);
6916 $tmp_hash = sprintf ("%s%s%s", $salt2, $hash_hmac, $salt_buf);
6918 elsif ($mode == 13000)
6920 my $iterations = 15;
6924 $iterations = int ($iter);
6929 if (defined $additional_param)
6931 $iv = $additional_param;
6934 my $pbkdf2 = Crypt::PBKDF2->new
6936 hasher => Crypt::PBKDF2->hasher_from_algorithm ('HMACSHA2', 256),
6937 iterations => (1 << $iterations) + 32,
6941 my $salt_buf_bin = pack ("H*", $salt_buf);
6943 my $hash = $pbkdf2->PBKDF2 ($salt_buf_bin, $word_buf);
6945 my $hash_final = substr ($hash, 0, 8)
6946 ^ substr ($hash, 8, 8)
6947 ^ substr ($hash, 16, 8)
6948 ^ substr ($hash, 24, 8);
6950 $tmp_hash = sprintf ('$rar5$16$%s$%d$%s$8$%s', $salt_buf, $iterations, $iv, unpack ("H*", $hash_final));
6952 elsif ($mode == 13100)
6954 my @salt_arr = split ('\$', $salt_buf);
6956 my $user = $salt_arr[0];
6958 my $realm = $salt_arr[1];
6960 my $spn = $salt_arr[2];
6962 my $k = md4 (encode ("UTF-16LE", $word_buf));
6964 my $k1 = hmac_md5 ("\x02\x00\x00\x00", $k);
6966 my $cleartext_ticket = '6381b03081ada00703050050a00000a11b3019a003020117a1'.
6967 '12041058e0d77776e8b8e03991f2966939222aa2171b154d594b5242544553542e434f4e5'.
6968 '44f534f2e434f4da3133011a003020102a10a30081b067472616e6365a40b3009a0030201'.
6969 '01a1020400a511180f32303136303231353134343735305aa611180f32303136303231353'.
6970 '134343735305aa711180f32303136303231363030343735305aa811180f32303136303232'.
6975 if (defined $additional_param)
6977 $checksum = pack ("H*", $additional_param);
6981 my $nonce = $salt_arr[3];
6983 $cleartext_ticket = $nonce . $cleartext_ticket;
6985 $checksum = hmac_md5 (pack ("H*", $cleartext_ticket), $k1);
6988 my $k3 = hmac_md5 ($checksum, $k1);
6992 if (defined $additional_param2)
6994 $edata2 = $additional_param2;
6996 my $cipher_decrypt = Crypt::RC4->new ($k3);
6998 my $ticket_decrypt = unpack ("H*", $cipher_decrypt->RC4 (pack ("H*", $edata2)));
7000 my $check_correct = ((substr ($ticket_decrypt, 16, 4) eq "6381" && substr ($ticket_decrypt, 22, 2) eq "30") ||
7001 (substr ($ticket_decrypt, 16, 4) eq "6382")) &&
7002 ((substr ($ticket_decrypt, 32, 6) eq "030500") ||
7003 (substr ($ticket_decrypt, 32, 8) eq "050307A0"));
7005 if ($check_correct == 1)
7007 $cleartext_ticket = $ticket_decrypt;
7009 else # validation failed
7011 # fake/wrong ticket (otherwise if we just decrypt/encrypt we end up with false positives all the time)
7012 $cleartext_ticket = "0" x (length ($cleartext_ticket) + 16);
7016 my $cipher = Crypt::RC4->new ($k3);
7018 $edata2 = $cipher->RC4 (pack ("H*", $cleartext_ticket));
7020 $tmp_hash = sprintf ('$krb5tgs$23$*%s$%s$%s*$%s$%s', $user, $realm, $spn, unpack ("H*", $checksum), unpack ("H*", $edata2));
7022 elsif ($mode == 13200)
7024 my @salt_arr = split ('\*', $salt_buf);
7026 my $iteration = $salt_arr[0];
7028 my $mysalt = $salt_arr[1];
7030 $mysalt = pack ("H*", $mysalt);
7032 my $iv = "a6a6a6a6a6a6a6a6";
7034 my $KEK = sha1 ($word_buf);
7036 $KEK = substr ($KEK ^ $mysalt, 0, 16);
7038 my $aes = Crypt::Mode::ECB->new ('AES');
7046 if (defined $additional_param)
7048 $additional_param = pack ("H*", $additional_param);
7050 $A = substr ($additional_param, 0, 8);
7053 $R[1] = substr ($additional_param, 8, 8);
7054 $R[2] = substr ($additional_param, 16, 8);
7056 for (my $j = $iteration - 1; $j >= 0; $j--)
7058 $A = substr ($A, 0, 8) ^ pack ("l", (2 * $j + 2));
7062 $A = $aes->decrypt ($A . $B . "\x00" x 16, $KEK);
7064 $R[2] = substr ($A, 8, 16);
7066 $A = substr ($A, 0, 8) ^ pack ("l", (2 * $j + 1));
7070 $A = $aes->decrypt ($A . $B . "\x00" x 16, $KEK);
7072 $R[1] = substr ($A, 8, 16);
7076 if (index ($A, "\xa6\xa6\xa6\xa6\xa6\xa6\xa6\xa6") != 0)
7078 # fake wrong @R and $A values
7080 @R = ('', "\x00" x 8, "\x00" x 8);
7087 my $DEK = randbytes (16);
7089 @R = ('', substr (pack ("H*", $DEK), 0, 8), substr (pack ("H*", $DEK), 8, 16));
7091 $A = pack ("H*", $iv);
7094 for (my $j = 0; $j < $iteration; $j++)
7096 $B = $aes->encrypt ($A . $R[1], $KEK);
7098 $A = substr ($B, 0, 8) ^ pack ("q", (2 * $j + 1));
7100 $R[1] = substr ($B, 8, 16);
7102 $B = $aes->encrypt ($A . $R[2], $KEK);
7104 $A = substr ($B, 0, 8) ^ pack ("q", (2 * $j + 2));
7106 $R[2] = substr ($B, 8, 16);
7109 my $wrapped_key = unpack ("H*", $A . substr ($R[1], 0 ,8) . substr ($R[2], 0 ,8));
7111 $mysalt = unpack ("H*", $mysalt);
7113 $tmp_hash = sprintf ('$axcrypt$*1*%s*%s*%s', $iteration, $mysalt, $wrapped_key);
7115 elsif ($mode == 13300)
7117 $hash_buf = sha1_hex ($word_buf);
7119 $tmp_hash = sprintf ('$axcrypt_sha1$%s', substr ($hash_buf, 0, 32));
7121 elsif ($mode == 13400)
7123 my @salt_arr = split ('\*', $salt_buf);
7125 my $version = $salt_arr[0];
7127 my $iteration = $salt_arr[1];
7129 my $algorithm = $salt_arr[2];
7131 my $final_random_seed = $salt_arr[3];
7133 my $transf_random_seed = $salt_arr[4];
7135 my $enc_iv = $salt_arr[5];
7139 # specific to version 1
7144 # specific to version 2
7147 # specific to keyfile handling
7148 my $inline_keyfile_flag;
7150 my $keyfile_content;
7151 my $keyfile_attributes = "";
7153 $final_random_seed = pack ("H*", $final_random_seed);
7155 $transf_random_seed = pack ("H*", $transf_random_seed);
7157 $enc_iv = pack ("H*", $enc_iv);
7159 my $intermediate_hash = sha256 ($word_buf);
7163 $contents_hash = $salt_arr[6];
7165 $contents_hash = pack ("H*", $contents_hash);
7167 $inline_flag = $salt_arr[7];
7170 $contents_len = $salt_arr[8];
7173 $contents = $salt_arr[9];
7175 $contents = pack ("H*", $contents);
7178 if (scalar @salt_arr == 13)
7180 $inline_keyfile_flag = $salt_arr[10];
7182 $keyfile_len = $salt_arr[11];
7184 $keyfile_content = $salt_arr[12];
7186 $keyfile_attributes = $keyfile_attributes
7187 . "*" . $inline_keyfile_flag
7188 . "*" . $keyfile_len
7189 . "*" . $keyfile_content;
7191 $intermediate_hash = $intermediate_hash . pack ("H*", $keyfile_content);
7193 $intermediate_hash = sha256 ($intermediate_hash);
7196 elsif ($version == 2)
7199 if (scalar @salt_arr == 11)
7201 $inline_keyfile_flag = $salt_arr[8];
7203 $keyfile_len = $salt_arr[9];
7205 $keyfile_content = $salt_arr[10];
7207 $intermediate_hash = $intermediate_hash . pack ("H*", $keyfile_content);
7209 $keyfile_attributes = $keyfile_attributes
7210 . "*" . $inline_keyfile_flag
7211 . "*" . $keyfile_len
7212 . "*" . $keyfile_content;
7216 $intermediate_hash = sha256 ($intermediate_hash);
7219 my $aes = Crypt::Mode::ECB->new ('AES', 1);
7221 for (my $j = 0; $j < $iteration; $j++)
7223 $intermediate_hash = $aes->encrypt ($intermediate_hash, $transf_random_seed);
7225 $intermediate_hash = substr ($intermediate_hash, 0, 32);
7228 $intermediate_hash = sha256 ($intermediate_hash);
7230 my $final_key = sha256 ($final_random_seed . $intermediate_hash);
7232 my $final_algorithm;
7234 if ($version == 1 && $algorithm == 1)
7236 $final_algorithm = "Crypt::Twofish";
7240 $final_algorithm = "Crypt::Rijndael";
7243 my $cipher = Crypt::CBC->new ({
7245 cipher => $final_algorithm,
7254 if (defined $additional_param)
7256 # if we try to verify the crack, we need to decrypt the contents instead of only encrypting it:
7258 $contents = $cipher->decrypt ($contents);
7260 # and check the output
7262 my $contents_hash_old = $contents_hash;
7264 $contents_hash = sha256 ($contents);
7266 if ($contents_hash_old ne $contents_hash)
7269 $contents = "\x00" x length ($contents);
7274 $contents_hash = sha256 ($contents);
7277 $contents = $cipher->encrypt ($contents);
7279 $tmp_hash = sprintf ('$keepass$*%d*%d*%d*%s*%s*%s*%s*%d*%d*%s%s',
7283 unpack ("H*", $final_random_seed),
7284 unpack ("H*", $transf_random_seed),
7285 unpack ("H*", $enc_iv),
7286 unpack ("H*", $contents_hash),
7289 unpack ("H*", $contents),
7290 $keyfile_attributes);
7294 $expected_bytes = $salt_arr[6];
7296 $contents_hash = $salt_arr[7];
7297 $contents_hash = pack ("H*", $contents_hash);
7299 $expected_bytes = $cipher->decrypt ($contents_hash);
7301 $tmp_hash = sprintf ('$keepass$*%d*%d*%d*%s*%s*%s*%s*%s%s',
7305 unpack ("H*", $final_random_seed),
7306 unpack ("H*", $transf_random_seed),
7307 unpack ("H*", $enc_iv),
7308 unpack ("H*", $expected_bytes),
7309 unpack ("H*", $contents_hash),
7310 $keyfile_attributes);
7313 elsif ($mode == 13500)
7315 $hash_buf = sha1_hex (pack ("H*", $salt_buf) . encode ("UTF-16LE", $word_buf));
7317 $tmp_hash = sprintf ("%s:%s", $hash_buf, $salt_buf);
7319 elsif ($mode == 13600)
7321 my $iterations = 1000;
7325 if (defined $additional_param)
7327 $type = $additional_param;
7330 my $mode = 1 + int rand (3);
7332 if (defined $additional_param2)
7334 $mode = $additional_param2;
7339 if (defined $additional_param3)
7341 $magic = $additional_param3;
7344 if (defined $additional_param4)
7346 $salt_buf = $additional_param4;
7349 $salt_buf = substr ($salt_buf, 0, 8 + ($mode * 8));
7351 my $compress_length = 0;
7353 if (defined $additional_param5)
7355 $compress_length = $additional_param5;
7360 if (defined $additional_param6)
7362 $data = $additional_param6;
7365 my $key_len = (8 * ($mode & 3) + 8) * 2;
7367 my $out_len = $key_len + 2;
7369 my $salt_buf_bin = pack ("H*", $salt_buf);
7371 my $hasher = Crypt::PBKDF2->hasher_from_algorithm ('HMACSHA1');
7373 my $pbkdf2 = Crypt::PBKDF2->new
7376 iterations => $iterations,
7377 output_len => $out_len
7380 my $key = $pbkdf2->PBKDF2_hex ($salt_buf_bin, $word_buf);
7382 my $verify_bytes = substr ($key, -4); $verify_bytes =~ s/^0+//; #lol
7384 $key = substr ($key, $key_len, $key_len);
7386 my $key_bin = pack ("H*", $key);
7388 my $auth = hmac_hex ($data, $key_bin, \&sha1, 64);
7390 $tmp_hash = sprintf ('$zip2$*%u*%u*%u*%s*%s*%u*%s*%s*$/zip2$', $type, $mode, $magic, $salt_buf, $verify_bytes, $compress_length, $data, substr ($auth, 0, 20));
7392 elsif ($mode == 13800)
7394 my $word_buf_unicode = encode ("UTF-16LE", $word_buf);
7396 my $salt_buf_bin = pack ("H*", $salt_buf);
7398 $hash_buf = sha256_hex ($word_buf_unicode . $salt_buf_bin);
7400 $tmp_hash = sprintf ("%s:%s", $hash_buf, $salt_buf);
7410 my $word_len = shift;
7412 my $salt_len = shift;
7416 $max = 15 if ($mode == 2410);
7418 if ($is_unicode{$mode})
7420 if (! $allow_long_salt{$mode})
7422 $word_len = min ($word_len, int ($max / 2) - $salt_len);
7426 $word_len = min ($word_len, int ($max / 2));
7429 elsif ($less_fifteen{$mode})
7431 $word_len = min ($word_len, 15);
7435 $salt_len = min ($salt_len, 15 - $word_len);
7440 if (! $allow_long_salt{$mode})
7442 $word_len = min ($word_len, $max - $salt_len);
7461 for (my $i = 0; $i < $salt_len; $i++)
7463 my $c = get_random_chr (0x30, 0x39);
7465 push (@salt_arr, $c);
7468 $salt_buf = join ("", @salt_arr);
7470 $salt_buf = get_random_md5chap_salt ($salt_buf);
7472 elsif ($mode == 5300 || $mode == 5400)
7474 $salt_buf = get_random_ike_salt ();
7476 elsif ($mode == 5500)
7478 $salt_buf = get_random_netntlmv1_salt ($salt_len, $salt_len);
7480 elsif ($mode == 5600)
7482 $salt_buf = get_random_netntlmv2_salt ($salt_len, $salt_len);
7484 elsif ($mode == 6600)
7486 $salt_buf = get_random_agilekeychain_salt ();
7488 elsif ($mode == 8200)
7490 $salt_buf = get_random_cloudkeychain_salt ();
7492 elsif ($mode == 8300)
7494 $salt_buf = get_random_dnssec_salt ();
7496 elsif ($mode == 13100)
7498 $salt_buf = get_random_kerberos5_tgs_salt ();
7500 elsif ($mode == 13200)
7502 $salt_buf = get_random_axcrypt_salt ();
7504 elsif ($mode == 13400)
7506 $salt_buf = get_random_keepass_salt ();
7508 elsif ($mode == 13500)
7510 $salt_buf = get_pstoken_salt ();
7516 for (my $i = 0; $i < $salt_len; $i++)
7518 my $c = get_random_chr (0x30, 0x39);
7520 push (@salt_arr, $c);
7523 $salt_buf = join ("", @salt_arr);
7527 $salt_buf = get_random_kerberos5_salt ($salt_buf);
7537 for (my $i = 0; $i < $word_len; $i++)
7539 my $c = get_random_chr (0x30, 0x39);
7541 push (@word_arr, $c);
7544 my $word_buf = join ("", @word_arr);
7550 my $tmp_hash = gen_hash ($mode, $word_buf, $salt_buf);
7563 print sprintf ("echo -n %-20s | %s \${OPTS} %s %4d '%s'\n", $word_buf, @cmd);
7575 sub get_random_string
7581 for (my $i = 0; $i < $len; $i++)
7583 my $c = get_random_chr (0x30, 0x39);
7588 my $buf = join ("", @arr);
7598 return int ((rand ($max - $min)) + $min);
7603 return chr get_random_num (@_);
7612 for (my $i = 0; $i < length ($str); $i += 4)
7614 my $num = domino_base64_decode (substr ($str, $i, 4), 4);
7616 $decoded .= chr (($num >> 16) & 0xff) . chr (($num >> 8) & 0xff) . chr ($num & 0xff);
7623 $salt = substr ($decoded, 0, 5);
7625 my $byte10 = (ord (substr ($salt, 3, 1)) - 4);
7629 $byte10 = 256 + $byte10;
7632 substr ($salt, 3, 1) = chr ($byte10);
7634 $digest = substr ($decoded, 5, 9);
7635 $char = substr ($str, 18, 1);
7637 return ($digest, $salt, $char);
7640 sub domino_85x_decode
7646 for (my $i = 0; $i < length ($str); $i += 4)
7648 my $num = domino_base64_decode (substr ($str, $i, 4), 4);
7650 $decoded .= chr (($num >> 16) & 0xff) . chr (($num >> 8) & 0xff) . chr ($num & 0xff);
7655 my $iterations = -1;
7658 $salt = substr ($decoded, 0, 16); # longer than -m 8700 (5 vs 16 <- new)
7660 my $byte10 = (ord (substr ($salt, 3, 1)) - 4);
7664 $byte10 = 256 + $byte10;
7667 substr ($salt, 3, 1) = chr ($byte10);
7669 $iterations = substr ($decoded, 16, 10);
7671 if ($iterations =~ /^?d*$/)
7675 $iterations = $iterations + 0; # hack: make sure it is an int now (atoi ())
7676 $chars = substr ($decoded, 26, 2); # in my example it is "02"
7677 $digest = substr ($decoded, 28, 8); # only of length of 8 vs 20 SHA1 bytes
7680 return ($digest, $salt, $iterations, $chars);
7683 sub domino_base64_decode
7688 my $itoa64 = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz+/";
7696 my $idx = (index ($itoa64, substr ($v, $n - $i, 1))) & 0x3f;
7698 $ret += ($idx << (6 * ($i - 1)));
7711 my $byte10 = (ord (substr ($final, 3, 1)) + 4);
7715 $byte10 = $byte10 - 256;
7718 substr ($final, 3, 1) = chr ($byte10);
7722 $passwd .= domino_base64_encode ((int (ord (substr ($final, 0, 1))) << 16) | (int (ord (substr ($final, 1, 1))) << 8) | (int (ord (substr ($final, 2, 1)))), 4);
7723 $passwd .= domino_base64_encode ((int (ord (substr ($final, 3, 1))) << 16) | (int (ord (substr ($final, 4, 1))) << 8) | (int (ord (substr ($final, 5, 1)))), 4);
7724 $passwd .= domino_base64_encode ((int (ord (substr ($final, 6, 1))) << 16) | (int (ord (substr ($final, 7, 1))) << 8) | (int (ord (substr ($final, 8, 1)))), 4);
7725 $passwd .= domino_base64_encode ((int (ord (substr ($final, 9, 1))) << 16) | (int (ord (substr ($final, 10, 1))) << 8) | (int (ord (substr ($final, 11, 1)))), 4);
7726 $passwd .= domino_base64_encode ((int (ord (substr ($final, 12, 1))) << 16) | (int (ord (substr ($final, 13, 1))) << 8) | (int (ord (substr ($final, 14, 1)))), 4);
7728 if (defined ($char))
7730 substr ($passwd, 18, 1) = $char;
7732 substr ($passwd, 19, 1) = "";
7737 sub domino_85x_encode
7742 my $byte10 = (ord (substr ($final, 3, 1)) + 4);
7746 $byte10 = $byte10 - 256;
7749 substr ($final, 3, 1) = chr ($byte10);
7753 $passwd .= domino_base64_encode ((int (ord (substr ($final, 0, 1))) << 16) | (int (ord (substr ($final, 1, 1))) << 8) | (int (ord (substr ($final, 2, 1)))), 4);
7754 $passwd .= domino_base64_encode ((int (ord (substr ($final, 3, 1))) << 16) | (int (ord (substr ($final, 4, 1))) << 8) | (int (ord (substr ($final, 5, 1)))), 4);
7755 $passwd .= domino_base64_encode ((int (ord (substr ($final, 6, 1))) << 16) | (int (ord (substr ($final, 7, 1))) << 8) | (int (ord (substr ($final, 8, 1)))), 4);
7756 $passwd .= domino_base64_encode ((int (ord (substr ($final, 9, 1))) << 16) | (int (ord (substr ($final, 10, 1))) << 8) | (int (ord (substr ($final, 11, 1)))), 4);
7757 $passwd .= domino_base64_encode ((int (ord (substr ($final, 12, 1))) << 16) | (int (ord (substr ($final, 13, 1))) << 8) | (int (ord (substr ($final, 14, 1)))), 4);
7758 $passwd .= domino_base64_encode ((int (ord (substr ($final, 15, 1))) << 16) | (int (ord (substr ($final, 16, 1))) << 8) | (int (ord (substr ($final, 17, 1)))), 4);
7759 $passwd .= domino_base64_encode ((int (ord (substr ($final, 18, 1))) << 16) | (int (ord (substr ($final, 19, 1))) << 8) | (int (ord (substr ($final, 20, 1)))), 4);
7760 $passwd .= domino_base64_encode ((int (ord (substr ($final, 21, 1))) << 16) | (int (ord (substr ($final, 22, 1))) << 8) | (int (ord (substr ($final, 23, 1)))), 4);
7761 $passwd .= domino_base64_encode ((int (ord (substr ($final, 24, 1))) << 16) | (int (ord (substr ($final, 25, 1))) << 8) | (int (ord (substr ($final, 26, 1)))), 4);
7762 $passwd .= domino_base64_encode ((int (ord (substr ($final, 27, 1))) << 16) | (int (ord (substr ($final, 28, 1))) << 8) | (int (ord (substr ($final, 29, 1)))), 4);
7763 $passwd .= domino_base64_encode ((int (ord (substr ($final, 30, 1))) << 16) | (int (ord (substr ($final, 31, 1))) << 8) | (int (ord (substr ($final, 32, 1)))), 4);
7764 $passwd .= domino_base64_encode ((int (ord (substr ($final, 33, 1))) << 16) | (int (ord (substr ($final, 34, 1))) << 8) | (int (ord (substr ($final, 35, 1)))), 4);
7766 if (defined ($char))
7768 substr ($passwd, 18, 1) = $char;
7774 sub domino_base64_encode
7779 my $itoa64 = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz+/";
7783 while (($n - 1) >= 0)
7787 $ret = substr ($itoa64, $v & 0x3f, 1) . $ret;
7797 my $itoa64 = "./0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
7802 my $v = unpack "V", substr($md5, $i*4, 4);
7804 $s64 .= substr($itoa64, $v & 0x3f, 1);
7813 my ($username, $password) = @_;
7815 $username = substr ($username . " " x 8, 0, 8);
7816 $password = substr ($password . " " x 8, 0, 8);
7818 my $username_ebc = ascii2ebcdic ($username);
7819 my $password_ebc = ascii2ebcdic ($password);
7821 my @pw = split ("", $password_ebc);
7823 for (my $i = 0; $i < 8; $i++)
7825 $pw[$i] = unpack ("C", $pw[$i]);
7828 $pw[$i] = pack ("C", $pw[$i] & 0xff);
7831 my $key = join ("", @pw);
7833 my $cipher = new Crypt::DES $key;
7835 my $ciphertext = $cipher->encrypt ($username_ebc);
7837 my $ct = unpack ("H16", $ciphertext);
7844 my ($username, $password) = @_;
7846 my $userpass = pack('n*', unpack('C*', uc($username.$password)));
7847 $userpass .= pack('C', 0) while (length($userpass) % 8);
7849 my $key = pack('H*', "0123456789ABCDEF");
7850 my $iv = pack('H*', "0000000000000000");
7852 my $c = new Crypt::CBC(
7859 my $key2 = substr($c->encrypt($userpass), length($userpass)-8, 8);
7861 my $c2 = new Crypt::CBC(
7868 my $hash = substr($c2->encrypt($userpass), length($userpass)-8, 8);
7870 return uc(unpack('H*', $hash));
7875 my $word_buf = shift;
7877 my $salt_buf = shift;
7879 my $w = sprintf ("%d%s%s", 0, $word_buf, $salt_buf);
7881 my $digest = sha1 ($w);
7883 for (my $i = 1; $i < 1024; $i++)
7885 $w = $digest . sprintf ("%d%s%s", $i, $word_buf, $salt_buf);
7887 $digest = sha1 ($w);
7890 my ($A, $B, $C, $D, $E) = unpack ("N5", $digest);
7892 return sprintf ("%08x%08x%08x%08x%08x", $A, $B, $C, $D, $E);
7900 my $itoa64 = "./0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
7904 while (($n - 1) >= 0)
7908 $ret .= substr ($itoa64, $v & 0x3f, 1);
7924 my $hash = ""; # hash to be returned by this function
7926 my $final = md5 ($pass . $salt . $pass);
7928 $salt = substr ($salt, 0, 8);
7930 my $tmp = $pass . $magic . $salt;
7932 my $pass_len = length ($pass);
7936 for ($i = $pass_len; $i > 0; $i -= 16)
7945 $tmp .= substr ($final, 0, $len);
7958 $tmp .= substr ($pass, 0, 1);
7964 $final = md5 ($tmp);
7966 for ($i = 0; $i < $iter; $i++)
7998 $final = md5 ($tmp);
8002 # now format the output sting ("hash")
8006 $hash = to64 ((ord (substr ($final, 0, 1)) << 16) | (ord (substr ($final, 6, 1)) << 8) | (ord (substr ($final, 12, 1))), 4);
8007 $hash .= to64 ((ord (substr ($final, 1, 1)) << 16) | (ord (substr ($final, 7, 1)) << 8) | (ord (substr ($final, 13, 1))), 4);
8008 $hash .= to64 ((ord (substr ($final, 2, 1)) << 16) | (ord (substr ($final, 8, 1)) << 8) | (ord (substr ($final, 14, 1))), 4);
8009 $hash .= to64 ((ord (substr ($final, 3, 1)) << 16) | (ord (substr ($final, 9, 1)) << 8) | (ord (substr ($final, 15, 1))), 4);
8010 $hash .= to64 ((ord (substr ($final, 4, 1)) << 16) | (ord (substr ($final, 10, 1)) << 8) | (ord (substr ($final, 5, 1))), 4);
8011 $hash .= to64 (ord (substr ($final, 11, 1)), 2);
8013 if ($iter == 1000) # default
8015 $hash_buf = sprintf ("%s%s\$%s", $magic , $salt , $hash);
8019 $hash_buf = sprintf ("%srounds=%i\$%s\$%s", $magic, $iter, $salt , $hash);
8031 my $hash = ""; # hash to be returned by this function
8033 my $final = sha512 ($pass . $salt . $pass);
8035 $salt = substr ($salt, 0, 16);
8037 my $tmp = $pass . $salt;
8039 my $pass_len = length ($pass);
8040 my $salt_len = length ($salt);
8044 for ($i = $pass_len; $i > 0; $i -= 16)
8053 $tmp .= substr ($final, 0, $len);
8072 $final = sha512 ($tmp);
8078 for ($i = 0; $i < $pass_len; $i++)
8083 $p_bytes = sha512 ($p_bytes);
8084 $p_bytes = substr ($p_bytes, 0, $pass_len);
8088 my $final_first_byte = ord (substr ($final, 0, 1));
8092 for ($i = 0; $i < (16 + $final_first_byte); $i++)
8097 $s_bytes = sha512 ($s_bytes);
8098 $s_bytes = substr ($s_bytes, 0, $salt_len);
8100 for ($i = 0; $i < $iter; $i++)
8132 $final = sha512 ($tmp);
8136 # now format the output string ("hash")
8140 $hash .= to64 ((ord (substr ($final, 0, 1)) << 16) | (ord (substr ($final, 21, 1)) << 8) | (ord (substr ($final, 42, 1))), 4);
8141 $hash .= to64 ((ord (substr ($final, 22, 1)) << 16) | (ord (substr ($final, 43, 1)) << 8) | (ord (substr ($final, 1, 1))), 4);
8142 $hash .= to64 ((ord (substr ($final, 44, 1)) << 16) | (ord (substr ($final, 2, 1)) << 8) | (ord (substr ($final, 23, 1))), 4);
8143 $hash .= to64 ((ord (substr ($final, 3, 1)) << 16) | (ord (substr ($final, 24, 1)) << 8) | (ord (substr ($final, 45, 1))), 4);
8144 $hash .= to64 ((ord (substr ($final, 25, 1)) << 16) | (ord (substr ($final, 46, 1)) << 8) | (ord (substr ($final, 4, 1))), 4);
8145 $hash .= to64 ((ord (substr ($final, 47, 1)) << 16) | (ord (substr ($final, 5, 1)) << 8) | (ord (substr ($final, 26, 1))), 4);
8146 $hash .= to64 ((ord (substr ($final, 6, 1)) << 16) | (ord (substr ($final, 27, 1)) << 8) | (ord (substr ($final, 48, 1))), 4);
8147 $hash .= to64 ((ord (substr ($final, 28, 1)) << 16) | (ord (substr ($final, 49, 1)) << 8) | (ord (substr ($final, 7, 1))), 4);
8148 $hash .= to64 ((ord (substr ($final, 50, 1)) << 16) | (ord (substr ($final, 8, 1)) << 8) | (ord (substr ($final, 29, 1))), 4);
8149 $hash .= to64 ((ord (substr ($final, 9, 1)) << 16) | (ord (substr ($final, 30, 1)) << 8) | (ord (substr ($final, 51, 1))), 4);
8150 $hash .= to64 ((ord (substr ($final, 31, 1)) << 16) | (ord (substr ($final, 52, 1)) << 8) | (ord (substr ($final, 10, 1))), 4);
8151 $hash .= to64 ((ord (substr ($final, 53, 1)) << 16) | (ord (substr ($final, 11, 1)) << 8) | (ord (substr ($final, 32, 1))), 4);
8152 $hash .= to64 ((ord (substr ($final, 12, 1)) << 16) | (ord (substr ($final, 33, 1)) << 8) | (ord (substr ($final, 54, 1))), 4);
8153 $hash .= to64 ((ord (substr ($final, 34, 1)) << 16) | (ord (substr ($final, 55, 1)) << 8) | (ord (substr ($final, 13, 1))), 4);
8154 $hash .= to64 ((ord (substr ($final, 56, 1)) << 16) | (ord (substr ($final, 14, 1)) << 8) | (ord (substr ($final, 35, 1))), 4);
8155 $hash .= to64 ((ord (substr ($final, 15, 1)) << 16) | (ord (substr ($final, 36, 1)) << 8) | (ord (substr ($final, 57, 1))), 4);
8156 $hash .= to64 ((ord (substr ($final, 37, 1)) << 16) | (ord (substr ($final, 58, 1)) << 8) | (ord (substr ($final, 16, 1))), 4);
8157 $hash .= to64 ((ord (substr ($final, 59, 1)) << 16) | (ord (substr ($final, 17, 1)) << 8) | (ord (substr ($final, 38, 1))), 4);
8158 $hash .= to64 ((ord (substr ($final, 18, 1)) << 16) | (ord (substr ($final, 39, 1)) << 8) | (ord (substr ($final, 60, 1))), 4);
8159 $hash .= to64 ((ord (substr ($final, 40, 1)) << 16) | (ord (substr ($final, 61, 1)) << 8) | (ord (substr ($final, 19, 1))), 4);
8160 $hash .= to64 ((ord (substr ($final, 62, 1)) << 16) | (ord (substr ($final, 20, 1)) << 8) | (ord (substr ($final, 41, 1))), 4);
8161 $hash .= to64 (ord (substr ($final, 63, 1)), 2);
8165 if ($iter == 5000) # default
8167 $hash_buf = sprintf ("%s%s\$%s", $magic, $salt , $hash);
8171 $hash_buf = sprintf ("%srounds=%i\$%s\$%s", $magic, $iter, $salt , $hash);
8183 my $hash = ""; # hash to be returned by this function
8185 my $final = sha256 ($pass . $salt . $pass);
8187 $salt = substr ($salt, 0, 16);
8189 my $tmp = $pass . $salt;
8191 my $pass_len = length ($pass);
8192 my $salt_len = length ($salt);
8196 for ($i = $pass_len; $i > 0; $i -= 16)
8205 $tmp .= substr ($final, 0, $len);
8224 $final = sha256 ($tmp);
8230 for ($i = 0; $i < $pass_len; $i++)
8235 $p_bytes = sha256 ($p_bytes);
8236 $p_bytes = substr ($p_bytes, 0, $pass_len);
8240 my $final_first_byte = ord (substr ($final, 0, 1));
8244 for ($i = 0; $i < (16 + $final_first_byte); $i++)
8249 $s_bytes = sha256 ($s_bytes);
8250 $s_bytes = substr ($s_bytes, 0, $salt_len);
8252 for ($i = 0; $i < $iter; $i++)
8284 $final = sha256 ($tmp);
8288 # now format the output string ("hash")
8292 $hash .= to64 ((ord (substr ($final, 0, 1)) << 16) | (ord (substr ($final, 10, 1)) << 8) | (ord (substr ($final, 20, 1))), 4);
8293 $hash .= to64 ((ord (substr ($final, 21, 1)) << 16) | (ord (substr ($final, 1, 1)) << 8) | (ord (substr ($final, 11, 1))), 4);
8294 $hash .= to64 ((ord (substr ($final, 12, 1)) << 16) | (ord (substr ($final, 22, 1)) << 8) | (ord (substr ($final, 2, 1))), 4);
8295 $hash .= to64 ((ord (substr ($final, 3, 1)) << 16) | (ord (substr ($final, 13, 1)) << 8) | (ord (substr ($final, 23, 1))), 4);
8296 $hash .= to64 ((ord (substr ($final, 24, 1)) << 16) | (ord (substr ($final, 4, 1)) << 8) | (ord (substr ($final, 14, 1))), 4);
8297 $hash .= to64 ((ord (substr ($final, 15, 1)) << 16) | (ord (substr ($final, 25, 1)) << 8) | (ord (substr ($final, 5, 1))), 4);
8298 $hash .= to64 ((ord (substr ($final, 6, 1)) << 16) | (ord (substr ($final, 16, 1)) << 8) | (ord (substr ($final, 26, 1))), 4);
8299 $hash .= to64 ((ord (substr ($final, 27, 1)) << 16) | (ord (substr ($final, 7, 1)) << 8) | (ord (substr ($final, 17, 1))), 4);
8300 $hash .= to64 ((ord (substr ($final, 18, 1)) << 16) | (ord (substr ($final, 28, 1)) << 8) | (ord (substr ($final, 8, 1))), 4);
8301 $hash .= to64 ((ord (substr ($final, 9, 1)) << 16) | (ord (substr ($final, 19, 1)) << 8) | (ord (substr ($final, 29, 1))), 4);
8302 $hash .= to64 ((ord (substr ($final, 31, 1)) << 8) | (ord (substr ($final, 30, 1))), 3);
8306 if ($iter == 5000) # default
8308 $hash_buf = sprintf ("%s%s\$%s", $magic, $salt , $hash);
8312 $hash_buf = sprintf ("%srounds=%i\$%s\$%s", $magic, $iter, $salt , $hash);
8318 sub aix_ssha256_pbkdf2
8320 my $word_buf = shift;
8321 my $salt_buf = shift;
8322 my $iterations = shift;
8324 my $hasher = Crypt::PBKDF2->hasher_from_algorithm ('HMACSHA2', 256);
8326 my $pbkdf2 = Crypt::PBKDF2->new (
8328 iterations => $iterations,
8332 my $hash_buf = $pbkdf2->PBKDF2 ($salt_buf, $word_buf);
8336 $tmp_hash .= to64 ((int (ord (substr ($hash_buf, 0, 1))) << 16) | (int (ord (substr ($hash_buf, 1, 1))) << 8) | (int (ord (substr ($hash_buf, 2, 1)))), 4);
8337 $tmp_hash .= to64 ((int (ord (substr ($hash_buf, 3, 1))) << 16) | (int (ord (substr ($hash_buf, 4, 1))) << 8) | (int (ord (substr ($hash_buf, 5, 1)))), 4);
8338 $tmp_hash .= to64 ((int (ord (substr ($hash_buf, 6, 1))) << 16) | (int (ord (substr ($hash_buf, 7, 1))) << 8) | (int (ord (substr ($hash_buf, 8, 1)))), 4);
8339 $tmp_hash .= to64 ((int (ord (substr ($hash_buf, 9, 1))) << 16) | (int (ord (substr ($hash_buf, 10, 1))) << 8) | (int (ord (substr ($hash_buf, 11, 1)))), 4);
8340 $tmp_hash .= to64 ((int (ord (substr ($hash_buf, 12, 1))) << 16) | (int (ord (substr ($hash_buf, 13, 1))) << 8) | (int (ord (substr ($hash_buf, 14, 1)))), 4);
8341 $tmp_hash .= to64 ((int (ord (substr ($hash_buf, 15, 1))) << 16) | (int (ord (substr ($hash_buf, 16, 1))) << 8) | (int (ord (substr ($hash_buf, 17, 1)))), 4);
8342 $tmp_hash .= to64 ((int (ord (substr ($hash_buf, 18, 1))) << 16) | (int (ord (substr ($hash_buf, 19, 1))) << 8) | (int (ord (substr ($hash_buf, 20, 1)))), 4);
8343 $tmp_hash .= to64 ((int (ord (substr ($hash_buf, 21, 1))) << 16) | (int (ord (substr ($hash_buf, 22, 1))) << 8) | (int (ord (substr ($hash_buf, 23, 1)))), 4);
8344 $tmp_hash .= to64 ((int (ord (substr ($hash_buf, 24, 1))) << 16) | (int (ord (substr ($hash_buf, 25, 1))) << 8) | (int (ord (substr ($hash_buf, 26, 1)))), 4);
8345 $tmp_hash .= to64 ((int (ord (substr ($hash_buf, 27, 1))) << 16) | (int (ord (substr ($hash_buf, 28, 1))) << 8) | (int (ord (substr ($hash_buf, 29, 1)))), 4);
8346 $tmp_hash .= to64 ((int (ord (substr ($hash_buf, 30, 1))) << 16) | (int (ord (substr ($hash_buf, 31, 1))) << 8) , 3);
8351 sub aix_ssha512_pbkdf2
8353 my $word_buf = shift;
8354 my $salt_buf = shift;
8355 my $iterations = shift;
8357 my $hasher = Crypt::PBKDF2->hasher_from_algorithm ('HMACSHA2', 512);
8359 my $pbkdf2 = Crypt::PBKDF2->new (
8361 iterations => $iterations,
8364 my $hash_buf = $pbkdf2->PBKDF2 ($salt_buf, $word_buf);
8368 $tmp_hash .= to64 ((int (ord (substr ($hash_buf, 0, 1))) << 16) | (int (ord (substr ($hash_buf, 1, 1))) << 8) | (int (ord (substr ($hash_buf, 2, 1)))), 4);
8369 $tmp_hash .= to64 ((int (ord (substr ($hash_buf, 3, 1))) << 16) | (int (ord (substr ($hash_buf, 4, 1))) << 8) | (int (ord (substr ($hash_buf, 5, 1)))), 4);
8370 $tmp_hash .= to64 ((int (ord (substr ($hash_buf, 6, 1))) << 16) | (int (ord (substr ($hash_buf, 7, 1))) << 8) | (int (ord (substr ($hash_buf, 8, 1)))), 4);
8371 $tmp_hash .= to64 ((int (ord (substr ($hash_buf, 9, 1))) << 16) | (int (ord (substr ($hash_buf, 10, 1))) << 8) | (int (ord (substr ($hash_buf, 11, 1)))), 4);
8372 $tmp_hash .= to64 ((int (ord (substr ($hash_buf, 12, 1))) << 16) | (int (ord (substr ($hash_buf, 13, 1))) << 8) | (int (ord (substr ($hash_buf, 14, 1)))), 4);
8373 $tmp_hash .= to64 ((int (ord (substr ($hash_buf, 15, 1))) << 16) | (int (ord (substr ($hash_buf, 16, 1))) << 8) | (int (ord (substr ($hash_buf, 17, 1)))), 4);
8374 $tmp_hash .= to64 ((int (ord (substr ($hash_buf, 18, 1))) << 16) | (int (ord (substr ($hash_buf, 19, 1))) << 8) | (int (ord (substr ($hash_buf, 20, 1)))), 4);
8375 $tmp_hash .= to64 ((int (ord (substr ($hash_buf, 21, 1))) << 16) | (int (ord (substr ($hash_buf, 22, 1))) << 8) | (int (ord (substr ($hash_buf, 23, 1)))), 4);
8376 $tmp_hash .= to64 ((int (ord (substr ($hash_buf, 24, 1))) << 16) | (int (ord (substr ($hash_buf, 25, 1))) << 8) | (int (ord (substr ($hash_buf, 26, 1)))), 4);
8377 $tmp_hash .= to64 ((int (ord (substr ($hash_buf, 27, 1))) << 16) | (int (ord (substr ($hash_buf, 28, 1))) << 8) | (int (ord (substr ($hash_buf, 29, 1)))), 4);
8378 $tmp_hash .= to64 ((int (ord (substr ($hash_buf, 30, 1))) << 16) | (int (ord (substr ($hash_buf, 31, 1))) << 8) | (int (ord (substr ($hash_buf, 32, 1)))), 4);
8379 $tmp_hash .= to64 ((int (ord (substr ($hash_buf, 33, 1))) << 16) | (int (ord (substr ($hash_buf, 34, 1))) << 8) | (int (ord (substr ($hash_buf, 35, 1)))), 4);
8380 $tmp_hash .= to64 ((int (ord (substr ($hash_buf, 36, 1))) << 16) | (int (ord (substr ($hash_buf, 37, 1))) << 8) | (int (ord (substr ($hash_buf, 38, 1)))), 4);
8381 $tmp_hash .= to64 ((int (ord (substr ($hash_buf, 39, 1))) << 16) | (int (ord (substr ($hash_buf, 40, 1))) << 8) | (int (ord (substr ($hash_buf, 41, 1)))), 4);
8382 $tmp_hash .= to64 ((int (ord (substr ($hash_buf, 42, 1))) << 16) | (int (ord (substr ($hash_buf, 43, 1))) << 8) | (int (ord (substr ($hash_buf, 44, 1)))), 4);
8383 $tmp_hash .= to64 ((int (ord (substr ($hash_buf, 45, 1))) << 16) | (int (ord (substr ($hash_buf, 46, 1))) << 8) | (int (ord (substr ($hash_buf, 47, 1)))), 4);
8384 $tmp_hash .= to64 ((int (ord (substr ($hash_buf, 48, 1))) << 16) | (int (ord (substr ($hash_buf, 49, 1))) << 8) | (int (ord (substr ($hash_buf, 50, 1)))), 4);
8385 $tmp_hash .= to64 ((int (ord (substr ($hash_buf, 51, 1))) << 16) | (int (ord (substr ($hash_buf, 52, 1))) << 8) | (int (ord (substr ($hash_buf, 53, 1)))), 4);
8386 $tmp_hash .= to64 ((int (ord (substr ($hash_buf, 54, 1))) << 16) | (int (ord (substr ($hash_buf, 55, 1))) << 8) | (int (ord (substr ($hash_buf, 56, 1)))), 4);
8387 $tmp_hash .= to64 ((int (ord (substr ($hash_buf, 57, 1))) << 16) | (int (ord (substr ($hash_buf, 58, 1))) << 8) | (int (ord (substr ($hash_buf, 59, 1)))), 4);
8388 $tmp_hash .= to64 ((int (ord (substr ($hash_buf, 60, 1))) << 16) | (int (ord (substr ($hash_buf, 61, 1))) << 8) | (int (ord (substr ($hash_buf, 62, 1)))), 4);
8389 $tmp_hash .= to64 ((int (ord (substr ($hash_buf, 63, 1))) << 16) , 2);
8394 sub aix_ssha1_pbkdf2
8396 my $word_buf = shift;
8397 my $salt_buf = shift;
8398 my $iterations = shift;
8400 my $hasher = Crypt::PBKDF2->hasher_from_algorithm ('HMACSHA1');
8402 my $pbkdf2 = Crypt::PBKDF2->new (
8404 iterations => $iterations,
8407 my $hash_buf = $pbkdf2->PBKDF2 ($salt_buf, $word_buf);
8411 $tmp_hash .= to64 ((int (ord (substr ($hash_buf, 0, 1))) << 16) | (int (ord (substr ($hash_buf, 1, 1))) << 8) | (int (ord (substr ($hash_buf, 2, 1)))), 4);
8412 $tmp_hash .= to64 ((int (ord (substr ($hash_buf, 3, 1))) << 16) | (int (ord (substr ($hash_buf, 4, 1))) << 8) | (int (ord (substr ($hash_buf, 5, 1)))), 4);
8413 $tmp_hash .= to64 ((int (ord (substr ($hash_buf, 6, 1))) << 16) | (int (ord (substr ($hash_buf, 7, 1))) << 8) | (int (ord (substr ($hash_buf, 8, 1)))), 4);
8414 $tmp_hash .= to64 ((int (ord (substr ($hash_buf, 9, 1))) << 16) | (int (ord (substr ($hash_buf, 10, 1))) << 8) | (int (ord (substr ($hash_buf, 11, 1)))), 4);
8415 $tmp_hash .= to64 ((int (ord (substr ($hash_buf, 12, 1))) << 16) | (int (ord (substr ($hash_buf, 13, 1))) << 8) | (int (ord (substr ($hash_buf, 14, 1)))), 4);
8416 $tmp_hash .= to64 ((int (ord (substr ($hash_buf, 15, 1))) << 16) | (int (ord (substr ($hash_buf, 16, 1))) << 8) | (int (ord (substr ($hash_buf, 17, 1)))), 4);
8417 $tmp_hash .= to64 ((int (ord (substr ($hash_buf, 18, 1))) << 16) | (int (ord (substr ($hash_buf, 19, 1))) << 8) , 3);
8426 my @data = split "", $data_s;
8429 "\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff" .
8430 "\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff" .
8431 "\x3f\x40\x41\x50\x43\x44\x45\x4b\x47\x48\x4d\x4e\x54\x51\x53\x46" .
8432 "\x35\x36\x37\x38\x39\x3a\x3b\x3c\x3d\x3e\x56\x55\x5c\x49\x5d\x4a" .
8433 "\x42\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f" .
8434 "\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x58\x5b\x59\xff\x52" .
8435 "\x4c\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f" .
8436 "\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x57\x5e\x5a\x4f\xff" .
8437 "\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff" .
8438 "\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff" .
8439 "\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff" .
8440 "\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff" .
8441 "\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff" .
8442 "\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff" .
8443 "\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff" .
8444 "\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff";
8446 my @transTable = unpack ("C256", $transTable_s);
8450 for (my $i = 0; $i < scalar @data; $i++)
8452 $out[$i] = $transTable[int (ord ($data[$i]))];
8455 return pack ("C*", @out);
8460 my $digest_s = shift;
8465 my @w = unpack "C*", $w_s;
8466 my @s = unpack "C*", $s_s;
8469 "\x14\x77\xf3\xd4\xbb\x71\x23\xd0\x03\xff\x47\x93\x55\xaa\x66\x91" .
8470 "\xf2\x88\x6b\x99\xbf\xcb\x32\x1a\x19\xd9\xa7\x82\x22\x49\xa2\x51" .
8471 "\xe2\xb7\x33\x71\x8b\x9f\x5d\x01\x44\x70\xae\x11\xef\x28\xf0\x0d";
8473 my @bcodeTable = unpack ("C48", $bcodeTable_s);
8475 my @abcd = unpack ("C16", $digest_s);
8477 my $sum20 = ($abcd[0] & 3)
8487 for (my $i2 = 0; $i2 < $sum20; $i2++)
8492 for (my $i1 = 0, my $i2 = 0, my $i3 = 0; $i2 < $sum20; $i2++, $i2++)
8494 if ($i1 < length $w_s)
8496 if ($abcd[15 - $i1] & 1)
8498 $out[$i2] = $bcodeTable[48 - 1 - $i1];
8503 $out[$i2] = $w[$i1];
8509 if ($i3 < length $s_s)
8511 $out[$i2] = $s[$i3];
8517 $out[$i2] = $bcodeTable[$i2 - $i1 - $i3];
8520 return substr (pack ("C*", @out), 0, $sum20);
8525 my @key_56 = split (//, shift);
8531 $key .= chr(((ord($key_56[0]) << 7) | (ord($key_56[1]) >> 1)) & 255);
8532 $key .= chr(((ord($key_56[1]) << 6) | (ord($key_56[2]) >> 2)) & 255);
8533 $key .= chr(((ord($key_56[2]) << 5) | (ord($key_56[3]) >> 3)) & 255);
8534 $key .= chr(((ord($key_56[3]) << 4) | (ord($key_56[4]) >> 4)) & 255);
8535 $key .= chr(((ord($key_56[4]) << 3) | (ord($key_56[5]) >> 5)) & 255);
8536 $key .= chr(((ord($key_56[5]) << 2) | (ord($key_56[6]) >> 6)) & 255);
8537 $key .= chr(( ord($key_56[6]) << 1) & 255);
8548 for (my $i = 0; $i < $len; $i++)
8550 my $c = get_random_chr (0, 255);
8555 return join ("", @arr);
8558 sub get_random_netntlmv1_salt
8560 my $len_user = shift;
8561 my $len_domain = shift;
8567 for (my $i = 0; $i < $len_user; $i++)
8569 $type = get_random_num (1, 3);
8573 $char = get_random_chr (0x30, 0x39);
8577 $char = get_random_chr (0x41, 0x5A);
8581 $char = get_random_chr (0x61, 0x7A);
8589 for (my $i = 0; $i < $len_domain; $i++)
8591 $type = get_random_num (1, 3);
8595 $char = get_random_chr (0x30, 0x39);
8599 $char = get_random_chr (0x41, 0x5A);
8603 $char = get_random_chr (0x61, 0x7A);
8609 my $c_challenge = randbytes (8);
8610 my $s_challenge = randbytes (8);
8612 my $salt_buf = $user . "::" . $domain . ":" . unpack ("H*", $c_challenge) . unpack ("H*", $s_challenge);
8617 sub get_random_netntlmv2_salt
8619 my $len_user = shift;
8620 my $len_domain = shift;
8626 if ($len_user + $len_domain > 27)
8628 if ($len_user > $len_domain)
8630 $len_user = 27 - $len_domain;
8634 $len_domain = 27 - $len_user;
8638 for (my $i = 0; $i < $len_user; $i++)
8640 $type = get_random_num (1, 3);
8644 $char = get_random_chr (0x30, 0x39);
8648 $char = get_random_chr (0x41, 0x5A);
8652 $char = get_random_chr (0x61, 0x7A);
8660 for (my $i = 0; $i < $len_domain; $i++)
8662 $type = get_random_num (1, 3);
8666 $char = get_random_chr (0x30, 0x39);
8670 $char = get_random_chr (0x41, 0x5A);
8674 $char = get_random_chr (0x61, 0x7A);
8680 my $c_challenge = randbytes (8);
8681 my $s_challenge = randbytes (8);
8683 my $temp = "\x01\x01" .
8688 randbytes (20 * rand () + 1) .
8691 my $salt_buf = $user . "::" . $domain . ":" . unpack ("H*", $s_challenge) . unpack ("H*", $temp);
8696 sub get_random_ike_salt
8700 for (my $i = 0; $i < 40; $i++)
8702 $nr_buf .= get_random_chr (0, 0xff);
8707 for (my $i = 0; $i < 440; $i++)
8709 $msg_buf .= get_random_chr (0, 0xff);
8712 my $nr_buf_hex = unpack ("H*", $nr_buf);
8713 my $msg_buf_hex = unpack ("H*", $msg_buf);
8715 my $salt_buf = sprintf ("%s:%s:%s:%s:%s:%s:%s:%s", substr ($msg_buf_hex, 0, 256), substr ($msg_buf_hex, 256, 256), substr ($msg_buf_hex, 512, 16), substr ($msg_buf_hex, 528, 16), substr ($msg_buf_hex, 544, 320), substr ($msg_buf_hex, 864, 16), substr ($nr_buf_hex, 0, 40), substr ($nr_buf_hex, 40, 40));
8720 sub get_random_agilekeychain_salt
8724 for (my $i = 0; $i < 8; $i++)
8726 $salt_buf .= get_random_chr (0x0, 0xff);
8731 for (my $i = 0; $i < 16; $i++)
8733 $iv .= get_random_chr (0x0, 0xff);
8736 my $prefix = "\x00" x 1008;
8738 my $ret = unpack ("H*", $salt_buf . $prefix . $iv);
8743 sub get_random_cloudkeychain_salt
8747 for (my $i = 0; $i < 16; $i++)
8749 $salt_buf .= get_random_chr (0x0, 0xff);
8752 for (my $i = 0; $i < 304; $i++)
8754 $salt_buf .= get_random_chr (0x0, 0xff);
8757 my $ret = unpack ("H*", $salt_buf);
8762 sub get_random_kerberos5_salt
8764 my $custom_salt = shift;
8766 my $clear_data = randbytes (14) .
8767 strftime ("%Y%m%d%H%M%S", localtime) .
8771 my $realm = "realm";
8774 my $salt_buf = $user . "\$" . $realm . "\$" . $salt . "\$" . unpack ("H*", $custom_salt) . "\$" . unpack ("H*", $clear_data) . "\$";
8779 sub get_random_kerberos5_tgs_salt
8781 my $nonce = randbytes (8);
8784 my $realm = "realm";
8785 my $spn = "test/spn";
8787 my $salt_buf = $user . "\$" . $realm . "\$" . $spn . "\$" . unpack ("H*", $nonce);
8792 sub get_random_axcrypt_salt
8794 my $mysalt = randbytes (16);
8796 $mysalt = unpack ("H*", $mysalt);
8798 my $iteration = get_random_num (6, 100000);
8800 my $salt_buf = $iteration . '*' . $mysalt;
8805 sub get_random_keepass_salt
8807 my $version = get_random_num (1, 3);
8813 my $final_random_seed;
8817 $algorithm = get_random_num (0, 2);
8819 $iteration = get_random_num (50000, 100000);
8821 $final_random_seed = randbytes (16);
8822 $final_random_seed = unpack ("H*", $final_random_seed);
8824 elsif ($version == 2)
8828 $iteration = get_random_num (6000, 100000);
8830 $final_random_seed = randbytes (32);
8831 $final_random_seed = unpack ("H*", $final_random_seed);
8834 my $transf_random_seed = randbytes (32);
8835 $transf_random_seed = unpack ("H*", $transf_random_seed);
8837 my $enc_iv = randbytes (16);
8838 $enc_iv = unpack ("H*", $enc_iv);
8840 my $contents_hash = randbytes (32);
8841 $contents_hash = unpack ("H*", $contents_hash);
8843 my $inline_flag = 1;
8845 my $contents_len = get_random_num (128, 500);
8847 my $contents = randbytes ($contents_len);
8849 $contents_len += 16 - $contents_len % 16;
8851 $contents = unpack ("H*", $contents);
8855 my $is_keyfile = get_random_num (0, 2);
8857 my $keyfile_attributes = "";
8859 if ($is_keyfile == 1)
8861 $keyfile_attributes = $keyfile_attributes
8863 . unpack ("H*", randbytes (32));
8868 $salt_buf = $version . '*' .
8871 $final_random_seed . '*' .
8872 $transf_random_seed . '*' .
8874 $contents_hash . '*' .
8875 $inline_flag . '*' .
8876 $contents_len . '*' .
8878 $keyfile_attributes;
8880 elsif ($version == 2)
8882 $contents = randbytes (32);
8883 $contents = unpack ("H*", $contents);
8885 $salt_buf = $version . '*' .
8888 $final_random_seed . '*' .
8889 $transf_random_seed . '*' .
8891 $contents_hash . '*' .
8893 $keyfile_attributes;
8899 sub get_pstoken_salt
8901 my $pstoken_length = get_random_num (16, 256);
8903 ## not a valid pstoken but a better test
8904 ## because of random length
8906 my $pstoken_const = randbytes ($pstoken_length);
8908 return unpack ("H*", $pstoken_const);
8911 sub get_random_md5chap_salt
8913 my $salt_buf = shift;
8915 my $salt = unpack ("H*", $salt_buf);
8919 $salt .= unpack ("H*", randbytes (1));
8924 sub get_random_dnssec_salt
8930 for (my $i = 0; $i < 8; $i++)
8932 $salt_buf .= get_random_chr (0x61, 0x7a);
8935 $salt_buf .= ".net";
8939 for (my $i = 0; $i < 8; $i++)
8941 $salt_buf .= get_random_chr (0x30, 0x39);
8954 my $byte_off = int ($bit / 8);
8955 my $bit_off = int ($bit % 8);
8957 my $char = substr ($digest, $byte_off, 1);
8958 my $num = ord ($char);
8960 return (($num & (1 << $bit_off)) ? 1 : 0);
8969 my $constant_phrase =
8970 "To be, or not to be,--that is the question:--\n" .
8971 "Whether 'tis nobler in the mind to suffer\n" .
8972 "The slings and arrows of outrageous fortune\n" .
8973 "Or to take arms against a sea of troubles,\n" .
8974 "And by opposing end them?--To die,--to sleep,--\n" .
8975 "No more; and by a sleep to say we end\n" .
8976 "The heartache, and the thousand natural shocks\n" .
8977 "That flesh is heir to,--'tis a consummation\n" .
8978 "Devoutly to be wish'd. To die,--to sleep;--\n" .
8979 "To sleep! perchance to dream:--ay, there's the rub;\n" .
8980 "For in that sleep of death what dreams may come,\n" .
8981 "When we have shuffled off this mortal coil,\n" .
8982 "Must give us pause: there's the respect\n" .
8983 "That makes calamity of so long life;\n" .
8984 "For who would bear the whips and scorns of time,\n" .
8985 "The oppressor's wrong, the proud man's contumely,\n" .
8986 "The pangs of despis'd love, the law's delay,\n" .
8987 "The insolence of office, and the spurns\n" .
8988 "That patient merit of the unworthy takes,\n" .
8989 "When he himself might his quietus make\n" .
8990 "With a bare bodkin? who would these fardels bear,\n" .
8991 "To grunt and sweat under a weary life,\n" .
8992 "But that the dread of something after death,--\n" .
8993 "The undiscover'd country, from whose bourn\n" .
8994 "No traveller returns,--puzzles the will,\n" .
8995 "And makes us rather bear those ills we have\n" .
8996 "Than fly to others that we know not of?\n" .
8997 "Thus conscience does make cowards of us all;\n" .
8998 "And thus the native hue of resolution\n" .
8999 "Is sicklied o'er with the pale cast of thought;\n" .
9000 "And enterprises of great pith and moment,\n" .
9001 "With this regard, their currents turn awry,\n" .
9002 "And lose the name of action.--Soft you now!\n" .
9003 "The fair Ophelia!--Nymph, in thy orisons\n" .
9004 "Be all my sins remember'd.\n\x00";
9006 my $constant_len = length ($constant_phrase);
9008 my $hash_buf = md5 ($pw . $salt);
9014 for (my $round = 0; $round < $iter; $round++)
9016 my $shift_a = md5bit ($hash_buf, $round + 0);
9017 my $shift_b = md5bit ($hash_buf, $round + 64);
9022 for (my $k = 0; $k < 16; $k++)
9024 my $s7shift = ord (substr ($hash_buf, $k, 1)) % 8;
9026 my $l = ($k + 3) % 16;
9028 my $num = ord (substr ($hash_buf, $l, 1));
9030 $shift_4[$k] = $num % 5;
9032 $shift_7[$k] = ($num >> $s7shift) & 1;
9037 for (my $k = 0; $k < 16; $k++)
9039 $indirect_4[$k] = (ord (substr ($hash_buf, $k, 1)) >> $shift_4[$k]) & 0xf;
9044 for (my $k = 0; $k < 16; $k++)
9046 $indirect_7[$k] = (ord (substr ($hash_buf, $indirect_4[$k], 1)) >> $shift_7[$k]) & 0x7f;
9052 for (my $k = 0; $k < 8; $k++)
9054 $indirect_a |= md5bit ($hash_buf, $indirect_7[$k + 0]) << $k;
9056 $indirect_b |= md5bit ($hash_buf, $indirect_7[$k + 8]) << $k;
9059 $indirect_a = ($indirect_a >> $shift_a) & 0x7f;
9060 $indirect_b = ($indirect_b >> $shift_b) & 0x7f;
9062 my $bit_a = md5bit ($hash_buf, $indirect_a);
9063 my $bit_b = md5bit ($hash_buf, $indirect_b);
9073 if ($bit_a ^ $bit_b)
9075 substr ($W, 16, 48) = substr ($constant_phrase, 0, 48);
9079 $to_hash .= substr ($W, 0, 64);
9083 for ($constant_off = 48; $constant_off < $constant_len - 64; $constant_off += 64)
9085 substr ($W, 0, 64) = substr ($constant_phrase, $constant_off, 64);
9089 $to_hash .= substr ($W, 0, 64);
9092 $pos = $constant_len - $constant_off;
9096 substr ($W, 0, $pos) = substr ($constant_phrase, $constant_off, $pos);
9111 my $round_div = int ($tmp / 10);
9112 my $round_mod = int ($tmp % 10);
9116 $a_buf[int ($a_len / 4)] = (($round_mod + 0x30) | ($a_buf[int ($a_len / 4)] << 8));
9126 for ($g = 0; $g < $a_len; $g++)
9128 my $remainder = $a_buf[$g];
9134 while ($remainder > 0)
9136 $sub = $remainder >> (8 * $factor);
9138 if ($started != 1 || $sub > 0)
9142 $tmp_str = chr ($sub) . $tmp_str;
9144 $remainder -= ($sub << (8 * $factor));
9152 substr ($W, $pos, $a_len) = $tmp_str;
9158 $to_hash .= substr ($W, 0, $pos);
9160 $to_hash = substr ($to_hash, 0, $total);
9162 $hash_buf = md5 ($to_hash);
9167 $passwd .= to64 ((int (ord (substr ($hash_buf, 0, 1))) << 16) | (int (ord (substr ($hash_buf, 6, 1))) << 8) | (int (ord (substr ($hash_buf, 12, 1)))), 4);
9168 $passwd .= to64 ((int (ord (substr ($hash_buf, 1, 1))) << 16) | (int (ord (substr ($hash_buf, 7, 1))) << 8) | (int (ord (substr ($hash_buf, 13, 1)))), 4);
9169 $passwd .= to64 ((int (ord (substr ($hash_buf, 2, 1))) << 16) | (int (ord (substr ($hash_buf, 8, 1))) << 8) | (int (ord (substr ($hash_buf, 14, 1)))), 4);
9170 $passwd .= to64 ((int (ord (substr ($hash_buf, 3, 1))) << 16) | (int (ord (substr ($hash_buf, 9, 1))) << 8) | (int (ord (substr ($hash_buf, 15, 1)))), 4);
9171 $passwd .= to64 ((int (ord (substr ($hash_buf, 4, 1))) << 16) | (int (ord (substr ($hash_buf, 10, 1))) << 8) | (int (ord (substr ($hash_buf, 5, 1)))), 4);
9172 $passwd .= to64 ((int (ord (substr ($hash_buf, 11, 1)))), 2);
9179 die ("usage: $0 single|passthrough| [mode] [len]\n" .
9181 " $0 verify [mode] [hashfile] [cracks] [outfile]\n");
9186 my $block_ref = shift;
9190 my $value = 16 - $offset;
9192 for (my $i = $offset; $i < 16; $i++)
9194 push @{$block_ref}, $value;
9204 for (my $i = 0; $i < 18; $i++)
9206 for (my $j = 0; $j < 48; $j++)
9208 $p = ($p + 48 - $j) & 0xff;
9210 my $c = $lotus_magic_table[$p];
9212 $p = $in_ref->[$j] ^ $c;
9219 sub lotus_transform_password
9222 my $out_ref = shift;
9224 my $t = $out_ref->[15];
9226 for (my $i = 0; $i < 16; $i++)
9228 $t ^= $in_ref->[$i];
9230 my $c = $lotus_magic_table[$t];
9232 $out_ref->[$i] ^= $c;
9234 $t = $out_ref->[$i];
9238 sub mdtransform_norecalc
9240 my $state_ref = shift;
9241 my $block_ref = shift;
9245 push (@x, @{$state_ref});
9246 push (@x, @{$block_ref});
9248 for (my $i = 0; $i < 16; $i++)
9250 push (@x, $x[0 + $i] ^ $x[16 + $i]);
9255 for (my $i = 0; $i < 16; $i++)
9257 $state_ref->[$i] = $x[$i];
9263 my $state_ref = shift;
9264 my $checksum_ref = shift;
9265 my $block_ref = shift;
9267 mdtransform_norecalc ($state_ref, $block_ref);
9269 lotus_transform_password ($block_ref, $checksum_ref);
9274 my $saved_key_ref = shift;
9278 @{$saved_key_ref} = splice (@{$saved_key_ref}, 0, $size);
9280 my @state = (0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
9286 for ($curpos = 0; $curpos + 16 < $size; $curpos += 16)
9288 my $curpos16 = $curpos + 16;
9290 my @block = splice (@{$saved_key_ref}, 0, 16);
9292 mdtransform (\@state, \@checksum, \@block);
9295 my $left = $size - $curpos;
9297 my @block = splice (@{$saved_key_ref}, 0, 16);
9299 pad16 (\@block, $left);
9301 mdtransform (\@state, \@checksum, \@block);
9303 mdtransform_norecalc (\@state, \@checksum);
9308 sub pdf_compute_encryption_key
9310 my $word_buf = shift;
9311 my $padding = shift;
9326 $data .= substr ($padding, 0, 32 - length $word_buf);
9328 $data .= pack ("H*", $o);
9330 $data .= pack ("I", $P);
9332 $data .= pack ("H*", $id);
9338 $data .= pack ("I", -1);
9342 my $res = md5 ($data);
9346 for (my $i = 0; $i < 50; $i++)
9355 sub gen_random_wpa_eapol
9364 my $version = 1; # 802.1X-2001
9366 $ret .= pack ("C*", $version);
9368 my $type = 3; # means that this EAPOL frame is used to transfer key information
9370 $ret .= pack ("C*", $type);
9372 my $length; # length of remaining data
9383 $ret .= pack ("n*", $length);
9385 my $descriptor_type;
9389 $descriptor_type = 254; # EAPOL WPA key
9393 $descriptor_type = 1; # EAPOL RSN key
9396 $ret .= pack ("C*", $descriptor_type);
9398 # key_info is a bit vector:
9399 # generated from these 13 bits: encrypted key data, request, error, secure, key mic, key ack, install, key index (2), key type, key descriptor (3)
9403 $key_info |= 1 << 8; # set key MIC
9404 $key_info |= 1 << 3; # set if it is a pairwise key
9408 $key_info |= 1 << 0; # RC4 Cipher, HMAC-MD5 MIC
9412 $key_info |= 1 << 1; # AES Cipher, HMAC-SHA1 MIC
9415 $ret .= pack ("n*", $key_info);
9428 $ret .= pack ("n*", $key_length);
9430 my $replay_counter = 1;
9432 $ret .= pack ("Q>*", $replay_counter);
9436 my $key_iv = "\x00" x 16;
9440 my $key_rsc = "\x00" x 8;
9444 my $key_id = "\x00" x 8;
9448 my $key_mic = "\x00" x 16;
9456 $key_data_len = 24; # length of the key_data (== WPA info)
9460 $key_data_len = 22; # length of the key_data (== RSN info)
9463 $ret .= pack ("n*", $key_data_len);
9473 my $vendor_specific_data = "";
9475 my $tag_number = 221; # means it is a vendor specific tag
9477 $vendor_specific_data .= pack ("C*", $tag_number);
9479 my $tag_len = 22; # length of the remaining "tag data"
9481 $vendor_specific_data .= pack ("C*", $tag_len);
9483 my $vendor_specific_oui = pack ("H*", "0050f2"); # microsoft
9485 $vendor_specific_data .= $vendor_specific_oui;
9487 my $vendor_specific_oui_type = 1; # WPA Information Element
9489 $vendor_specific_data .= pack ("C*", $vendor_specific_oui_type);
9491 my $vendor_specific_wpa_version = 1;
9493 $vendor_specific_data .= pack ("v*", $vendor_specific_wpa_version);
9497 my $vendor_specific_multicast_oui = pack ("H*", "0050f2");
9499 $vendor_specific_data .= $vendor_specific_multicast_oui;
9501 my $vendor_specific_multicast_type = 2; # TKIP
9503 $vendor_specific_data .= pack ("C*", $vendor_specific_multicast_type);
9507 my $vendor_specific_unicast_count = 1;
9509 $vendor_specific_data .= pack ("v*", $vendor_specific_unicast_count);
9511 my $vendor_specific_unicast_oui = pack ("H*", "0050f2");
9513 $vendor_specific_data .= $vendor_specific_multicast_oui;
9515 my $vendor_specific_unicast_type = 2; # TKIP
9517 $vendor_specific_data .= pack ("C*", $vendor_specific_unicast_type);
9519 # Auth Key Management (AKM)
9521 my $auth_key_management_count = 1;
9523 $vendor_specific_data .= pack ("v*", $auth_key_management_count);
9525 my $auth_key_management_oui = pack ("H*", "0050f2");
9527 $vendor_specific_data .= $auth_key_management_oui;
9529 my $auth_key_management_type = 2; # Pre-Shared Key (PSK)
9531 $vendor_specific_data .= pack ("C*", $auth_key_management_type);
9533 $wpa_info = $vendor_specific_data;
9535 $key_data = $wpa_info;
9543 my $tag_number = 48; # RSN info
9545 $rsn_info .= pack ("C*", $tag_number);
9547 my $tag_len = 20; # length of the remaining "tag_data"
9549 $rsn_info .= pack ("C*", $tag_len);
9551 my $rsn_version = 1;
9553 $rsn_info .= pack ("v*", $rsn_version);
9555 # group cipher suite
9557 my $group_cipher_suite_oui = pack ("H*", "000fac"); # Ieee8021
9559 $rsn_info .= $group_cipher_suite_oui;
9561 my $group_cipher_suite_type = 4; # AES (CCM)
9563 $rsn_info .= pack ("C*", $group_cipher_suite_type);
9565 # pairwise cipher suite
9567 my $pairwise_cipher_suite_count = 1;
9569 $rsn_info .= pack ("v*", $pairwise_cipher_suite_count);
9571 my $pairwise_cipher_suite_oui = pack ("H*", "000fac"); # Ieee8021
9573 $rsn_info .= $pairwise_cipher_suite_oui;
9575 my $pairwise_cipher_suite_type = 4; # AES (CCM)
9577 $rsn_info .= pack ("C*", $pairwise_cipher_suite_type);
9579 # Auth Key Management (AKM)
9581 my $auth_key_management_count = 1;
9583 $rsn_info .= pack ("v*", $auth_key_management_count);
9585 my $auth_key_management_oui = pack ("H*", "000fac"); # Ieee8021
9587 $rsn_info .= $auth_key_management_oui;
9589 my $auth_key_management_type = 2; # Pre-Shared Key (PSK)
9591 $rsn_info .= pack ("C*", $auth_key_management_type);
9595 # bit vector of these 9 bits: peerkey enabled, management frame protection (MFP) capable, MFP required,
9596 # RSN GTKSA Capabilities (2), RSN PTKSA Capabilities (2), no pairwise Capabilities, Pre-Auth Capabilities
9598 my $rsn_capabilities = pack ("H*", "0000");
9600 $rsn_info .= $rsn_capabilities;
9602 $key_data = $rsn_info;
9618 my $data = "Pairwise key expansion";
9623 # Min(AA, SPA) || Max(AA, SPA)
9626 # compare if greater: Min()/Max() on the MACs (6 bytes)
9628 if (memcmp ($stmac, $bssid, 6) < 0)
9640 # Min(ANonce,SNonce) || Max(ANonce,SNonce)
9643 # compare if greater: Min()/Max() on the nonces (32 bytes)
9645 if (memcmp ($snonce, $anonce, 32) < 0)
9658 my $prf_buf = hmac ($data, $pmk, \&sha1);
9660 $prf_buf = substr ($prf_buf, 0, 16);
9671 my $len_str1 = length ($str1);
9672 my $len_str2 = length ($str2);
9674 if (($len > $len_str1) || ($len > $len_str2))
9676 print "ERROR: memcmp () lengths wrong";
9681 for (my $i = 0; $i < $len; $i++)
9683 my $c_1 = ord (substr ($str1, $i, 1));
9684 my $c_2 = ord (substr ($str2, $i, 1));
9686 return -1 if ($c_1 < $c_2);
9687 return 1 if ($c_1 > $c_2);