|
16 | 16 | using NtApiDotNet.Utilities.Security; |
17 | 17 | using NtApiDotNet.Utilities.Text; |
18 | 18 | using System; |
19 | | -using System.ComponentModel; |
20 | 19 | using System.IO; |
| 20 | +using System.Linq; |
21 | 21 | using System.Security.Cryptography; |
22 | 22 | using System.Text; |
23 | 23 |
|
@@ -93,16 +93,6 @@ private bool DecryptRC4WithKey(KerberosKey key, KeyUsage key_usage, out byte[] d |
93 | 93 | private const int AES_CHECKSUM_SIZE = 12; |
94 | 94 | private const int AES_CONFOUNDER_SIZE = 16; |
95 | 95 |
|
96 | | - private static byte[] _aes_encrypt_ticket = new byte[] { 0xB5, 0xB0, 0x58, 0x2C, 0x14, 0xB6, 0x50, 0x0A, 0xAD, 0x56, 0xAB, 0x55, 0xAA, 0x80, 0x55, 0x6A }; |
97 | | - private static byte[] _aes_verify_ticket = new byte[] { 0x62, 0xDC, 0x6E, 0x37, 0x1A, 0x63, 0xA8, 0x09, 0x58, 0xAC, 0x56, 0x2B, 0x15, 0x40, 0x4A, 0xC5 }; |
98 | | - private static byte[] _aes_encrypt_auth = new byte[] { 0xFE, 0x54, 0xAA, 0x55, 0xA5, 0x02, 0x52, 0x2F, 0xBF, 0x5F, 0xAF, 0xD7, 0xEA, 0x81, 0x75, 0xFA }; |
99 | | - private static byte[] _aes_verify_auth = new byte[] { 0xAB, 0x80, 0xC0, 0x60, 0xAA, 0xAF, 0xAA, 0x2E, 0x6A, 0xB5, 0x5A, 0xAD, 0x55, 0x41, 0x6B, 0x55 }; |
100 | | - |
101 | | - private static byte[] _aes_encrypt_ap_rep = new byte[] { 0x05, 0xD7, 0xEC, 0x76, 0xB5, 0x0B, 0x53, 0x33, 0xC1, 0x60, 0xB0, 0x58, 0x2A, 0x81, 0x96, 0x0B }; |
102 | | - private static byte[] _aes_verify_ap_rep = new byte[] { 0xB3, 0x04, 0x02, 0x81, 0xBA, 0xB8, 0xAB, 0x32, 0x6C, 0xB6, 0x5B, 0x2D, 0x95, 0x41, 0x8B, 0x65 }; |
103 | | - private static byte[] _aes_encrypt_krb_cred = new byte[] { 0x15, 0xE0, 0x70, 0xB8, 0xD5, 0x1C, 0x53, 0x3B, 0xC5, 0x62, 0xB1, 0x58, 0xAA, 0x81, 0xD6, 0x2B }; |
104 | | - private static byte[] _aes_verify_krb_cred = new byte[] { 0xC3, 0x0C, 0x86, 0xC3, 0xDA, 0xC9, 0xAB, 0x3A, 0x70, 0xB8, 0x5C, 0x2E, 0x15, 0x41, 0xCB, 0x85 }; |
105 | | - |
106 | 96 | private static void SwapEndBlocks(byte[] cipher_text) |
107 | 97 | { |
108 | 98 | if (cipher_text.Length < AES_BLOCK_SIZE*2) |
@@ -134,32 +124,21 @@ private byte[] DecryptAESBlock(byte[] key, byte[] cipher_text, int offset) |
134 | 124 | return block; |
135 | 125 | } |
136 | 126 |
|
137 | | - private bool DecryptAESWithKey(KerberosKey key, KeyUsage key_usage, out byte[] decrypted) |
| 127 | + private const byte EncryptionKey = 0xAA; |
| 128 | + private const byte VerificationKey = 0x55; |
| 129 | + |
| 130 | + private byte[] DeriveTempKey(KerberosKey key, KeyUsage key_usage, byte key_type) |
138 | 131 | { |
139 | | - byte[] derive_enc_key; |
140 | | - byte[] derive_mac_key; |
| 132 | + byte[] r = BitConverter.GetBytes((int)key_usage).Reverse().ToArray(); |
| 133 | + Array.Resize(ref r, 5); |
| 134 | + r[4] = key_type; |
| 135 | + return NFold.Compute(r, 16); |
| 136 | + } |
141 | 137 |
|
142 | | - switch (key_usage) |
143 | | - { |
144 | | - case KeyUsage.AsRepTgsRepTicket: |
145 | | - derive_enc_key = _aes_encrypt_ticket; |
146 | | - derive_mac_key = _aes_verify_ticket; |
147 | | - break; |
148 | | - case KeyUsage.ApReqAuthSubKey: |
149 | | - derive_enc_key = _aes_encrypt_auth; |
150 | | - derive_mac_key = _aes_verify_auth; |
151 | | - break; |
152 | | - case KeyUsage.ApRepEncryptedPart: |
153 | | - derive_enc_key = _aes_encrypt_ap_rep; |
154 | | - derive_mac_key = _aes_verify_ap_rep; |
155 | | - break; |
156 | | - case KeyUsage.KrbCred: |
157 | | - derive_enc_key = _aes_encrypt_krb_cred; |
158 | | - derive_mac_key = _aes_verify_krb_cred; |
159 | | - break; |
160 | | - default: |
161 | | - throw new ArgumentException("Unknown key usage type."); |
162 | | - } |
| 138 | + private bool DecryptAESWithKey(KerberosKey key, KeyUsage key_usage, out byte[] decrypted) |
| 139 | + { |
| 140 | + byte[] derive_enc_key = DeriveTempKey(key, key_usage, EncryptionKey); |
| 141 | + byte[] derive_mac_key = DeriveTempKey(key, key_usage, VerificationKey); |
163 | 142 |
|
164 | 143 | byte[] new_key = KerberosKey.DeriveAesKey(key.Key, derive_enc_key); |
165 | 144 |
|
|
0 commit comments