rusthound_ce/utils/
crypto.rs

1use sha1::{Sha1, Digest};
2
3/// Easy function to get SHA1 hash
4pub fn calculate_sha1(data: &[u8]) -> String {
5    let mut hasher = Sha1::new();
6    hasher.update(data);
7    format!("{:X}", hasher.finalize())
8}
9
10/// Return encryption type msDS-SupportedEncryptionTypes to BloodHound-CE string format.
11/// <https://github.com/SpecterOps/SharpHoundCommon/blob/c953260325cbfd335ed2e9726cfe28d4b16357c8/src/CommonLib/Processors/LdapPropertyProcessor.cs#L731>
12pub fn convert_encryption_types(encryption_types: i32) -> Vec<String> {
13    // Define Kerberos Encryption Types as constants
14    const DES_CBC_CRC: i32 = 0x1;
15    const DES_CBC_MD5: i32 = 0x2;
16    const RC4_HMAC_MD5: i32 = 0x4;
17    const AES128_CTS_HMAC_SHA1_96: i32 = 0x8;
18    const AES256_CTS_HMAC_SHA1_96: i32 = 0x10;
19
20    let mut supported_encryption_types = Vec::new();
21
22    if encryption_types == 0 {
23        supported_encryption_types.push("Not defined".to_string());
24    }
25
26    if (encryption_types & DES_CBC_CRC) == DES_CBC_CRC {
27        supported_encryption_types.push("DES-CBC-CRC".to_string());
28    }
29
30    if (encryption_types & DES_CBC_MD5) == DES_CBC_MD5 {
31        supported_encryption_types.push("DES-CBC-MD5".to_string());
32    }
33
34    if (encryption_types & RC4_HMAC_MD5) == RC4_HMAC_MD5 {
35        supported_encryption_types.push("RC4-HMAC-MD5".to_string());
36    }
37
38    if (encryption_types & AES128_CTS_HMAC_SHA1_96) == AES128_CTS_HMAC_SHA1_96 {
39        supported_encryption_types.push("AES128-CTS-HMAC-SHA1-96".to_string());
40    }
41
42    if (encryption_types & AES256_CTS_HMAC_SHA1_96) == AES256_CTS_HMAC_SHA1_96 {
43        supported_encryption_types.push("AES256-CTS-HMAC-SHA1-96".to_string());
44    }
45
46    supported_encryption_types
47}