|
| 1 | +module RubySMB |
| 2 | + module Dcerpc |
| 3 | + module Gkdi |
| 4 | + |
| 5 | + # [2.2.4 Group Key Envelope](https://learn.microsoft.com/en-us/openspecs/windows_protocols/ms-gkdi/192c061c-e740-4aa0-ab1d-6954fb3e58f7) |
| 6 | + class GkdiGroupKeyEnvelope < BinData::Record |
| 7 | + endian :little |
| 8 | + |
| 9 | + uint32 :version |
| 10 | + uint8_array :magic, initial_length: 4, initial_value: [ 0x4b, 0x44, 0x53, 0x5b ] |
| 11 | + uint32 :dw_flags |
| 12 | + uint32 :l0_index |
| 13 | + uint32 :l1_index |
| 14 | + uint32 :l2_index |
| 15 | + uuid :root_key_identifier |
| 16 | + uint32 :cb_kdf_algorithm |
| 17 | + uint32 :cb_kdf_parameters, initial_value: -> { kdf_parameters.length } |
| 18 | + uint32 :cb_secret_agreement_algorithm |
| 19 | + uint32 :cb_secret_agreement_parameters |
| 20 | + uint32 :private_key_length |
| 21 | + uint32 :public_key_length |
| 22 | + uint32 :cb_l1_key |
| 23 | + uint32 :cb_l2_key |
| 24 | + uint32 :cb_domain_name |
| 25 | + uint32 :cb_forest_name |
| 26 | + stringz16 :kdf_algorithm |
| 27 | + struct :kdf_parameters, only_if: -> { cb_kdf_parameters > 0 } do |
| 28 | + uint8_array :block0, initial_length: 8, initial_value: [ 0, 0, 0, 0, 1, 0, 0, 0 ] |
| 29 | + uint32 :length_of_hash_name, initial_value: -> { hash_algorithm_name.length } |
| 30 | + uint8_array :block1, initial_length: 4, initial_value: [ 0, 0, 0, 0 ] |
| 31 | + stringz16 :hash_algorithm_name |
| 32 | + end |
| 33 | + stringz16 :secret_agreement_algorithm |
| 34 | + uint8_array :secret_agreement_parameters, initial_length: :cb_secret_agreement_parameters |
| 35 | + stringz16 :domain_name |
| 36 | + stringz16 :forest_name |
| 37 | + uint8_array :l1_key, initial_length: 64, only_if: -> { cb_l1_key != 0 } |
| 38 | + uint8_array :l2_key, initial_length: :l2_key_length, only_if: -> { cb_l2_key != 0 } |
| 39 | + |
| 40 | + private |
| 41 | + |
| 42 | + def l2_key_length |
| 43 | + return 0 if cb_l2_key == 0 |
| 44 | + return 64 if (dw_flags & (1 << 31)) == 0 |
| 45 | + |
| 46 | + public_key_length |
| 47 | + end |
| 48 | + end |
| 49 | + end |
| 50 | + end |
| 51 | +end |
0 commit comments