From 6c86243b9be2c6e6c5a5ef8c7f8817782f0ab2a6 Mon Sep 17 00:00:00 2001 From: jsteube Date: Sat, 20 Jan 2018 21:41:10 +0100 Subject: [PATCH] Prepare for JWT --- tools/test.pl | 106 +++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 104 insertions(+), 2 deletions(-) diff --git a/tools/test.pl b/tools/test.pl index cde43d623..d5225b23d 100755 --- a/tools/test.pl +++ b/tools/test.pl @@ -33,6 +33,7 @@ use Crypt::Mode::ECB; use Crypt::UnixCrypt_XS qw (crypt_rounds fold_password base64_to_int24 block_to_base64 int24_to_base64); use Crypt::Skip32; use Crypt::OpenSSH::ChachaPoly; +use JSON; use MIME::Base64; use Authen::Passphrase::NTHash; use Authen::Passphrase::MySQL323; @@ -51,7 +52,7 @@ my $hashcat = "./hashcat"; my $MAX_LEN = 55; -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, 600, 900, 1000, 1100, 1300, 1400, 1410, 1411, 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, 4520, 4521, 4522, 4600, 4700, 4800, 4900, 5000, 5100, 5300, 5400, 5500, 5600, 5700, 5800, 6000, 6100, 6300, 6400, 6500, 6600, 6700, 6800, 6900, 7000, 7100, 7200, 7300, 7400, 7500, 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, 12001, 12100, 12200, 12300, 12400, 12600, 12700, 12800, 12900, 13000, 13100, 13200, 13300, 13400, 13500, 13600, 13800, 13900, 14000, 14100, 14400, 14700, 14800, 14900, 15000, 15100, 15200, 15300, 15400, 15500, 15600, 15700, 15900, 16000, 16100, 16200, 16300, 16400, 99999); +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, 600, 900, 1000, 1100, 1300, 1400, 1410, 1411, 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, 4520, 4521, 4522, 4600, 4700, 4800, 4900, 5000, 5100, 5300, 5400, 5500, 5600, 5700, 5800, 6000, 6100, 6300, 6400, 6500, 6600, 6700, 6800, 6900, 7000, 7100, 7200, 7300, 7400, 7500, 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, 12001, 12100, 12200, 12300, 12400, 12600, 12700, 12800, 12900, 13000, 13100, 13200, 13300, 13400, 13500, 13600, 13800, 13900, 14000, 14100, 14400, 14700, 14800, 14900, 15000, 15100, 15200, 15300, 15400, 15500, 15600, 15700, 15900, 16000, 16100, 16200, 16300, 16400, 16500, 99999); my %is_utf16le = 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); my %less_fifteen = map { $_ => 1 } qw (500 1600 1800 3200 6300 7400 10500 10700); @@ -2870,6 +2871,24 @@ sub verify next unless (exists ($db->{$hash_in}) and (! defined ($db->{$hash_in}))); } + # JWT + elsif ($mode == 16500) + { + ($hash_in, $word) = split ":", $line; + + next unless defined $hash_in; + next unless defined $word; + + my @data = split (/\./, $hash_in); + + next unless scalar @data == 3; + + my ($header, $payload, $signature) = @data; + + $salt = $header . "." . $payload; + + next unless (exists ($db->{$hash_in}) and (! defined ($db->{$hash_in}))); + } else { print "ERROR: hash mode is not supported\n"; @@ -3872,6 +3891,12 @@ sub passthrough { $tmp_hash = gen_hash ($mode, $word_buf, substr ($salt_buf, 0, 32)); } + elsif ($mode == 16500) + { + $salt_buf = get_random_jwt_salt (); + + $tmp_hash = gen_hash ($mode, $word_buf, $salt_buf); + } else { print "ERROR: Unsupported hash type\n"; @@ -3910,7 +3935,7 @@ sub single } } } - 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 == 1411 || $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 == 3910 || $mode == 4010 || $mode == 4110 || $mode == 4210 || $mode == 8900 || $mode == 10000 || $mode == 10200 || $mode == 10900 || $mode == 11900 || $mode == 12000 || $mode == 12100) + 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 == 1411 || $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 == 3910 || $mode == 4010 || $mode == 4110 || $mode == 4210 || $mode == 8900 || $mode == 10000 || $mode == 10200 || $mode == 10900 || $mode == 11900 || $mode == 12000 || $mode == 12100 || $mode == 16500) { my $salt_len = get_random_num (1, 15); @@ -9347,6 +9372,35 @@ END_CODE $hash_buf = unpack("H*", pack('V4', @{$md5->{_state}})); $tmp_hash = sprintf ("{CRAM-MD5}%s00000000000000000000000000000000", $hash_buf); } + elsif ($mode == 16500) + { + my ($header_base64) = split (/\./, $salt_buf); + + my $header_jwt = decode_base64 ($header_base64); + + my $header = decode_json ($header_jwt); + + my $alg = $header->{"alg"}; + + if ($alg eq "HS256") + { + $hash_buf = hmac_hex ($salt_buf, $word_buf, \&sha256, 64); + } + elsif ($alg eq "HS384") + { + $hash_buf = hmac_hex ($salt_buf, $word_buf, \&sha384, 128); + } + elsif ($alg eq "HS512") + { + $hash_buf = hmac_hex ($salt_buf, $word_buf, \&sha512, 128); + } + else + { + die "not supported hash\n"; + } + + $tmp_hash = sprintf ("%s.%s", $salt_buf, $hash_buf); + } elsif ($mode == 99999) { $tmp_hash = sprintf ("%s", $word_buf); @@ -9498,6 +9552,10 @@ sub rnd $salt_buf = get_random_dpapimk_salt ($version); } + elsif ($mode == 16500) + { + $salt_buf = get_random_jwt_salt (); + } else { my @salt_arr; @@ -10996,6 +11054,50 @@ sub get_random_dpapimk_salt return $salt_buf; } +sub get_random_jwt_salt +{ + my @hashes = + ( + "HS256", + "HS384", + "HS512", + #"RS256", #not supported by hashcat + #"RS384", + #"RS512", + #"PS256", + #"PS384", + #"PS512", + #"ES256", + #"ES384", + #"ES512", + ); + + my $rnd = get_random_num (0, scalar @hashes); + + my $hash = $hashes[$rnd]; + + my $header = + { + "alg" => $hash + }; + + my $random_key = get_random_num (1, 100000000); + my $random_val = get_random_num (1, 100000000); + + my $payload = + { + $random_key => $random_val + }; + + my $header_json = encode_json ($header); + my $payload_json = encode_json ($payload); + + my $header_base64 = encode_base64 ($header_json, ""); + my $payload_base64 = encode_base64 ($payload_json, ""); + + return $header_base64 . "." . $payload_base64; +} + sub md5bit { my $digest = shift;