ruby_smb 3.3.7 → 3.3.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (39) hide show
  1. checksums.yaml +4 -4
  2. checksums.yaml.gz.sig +0 -0
  3. data/README.md +14 -0
  4. data/lib/ruby_smb/dcerpc/error.rb +3 -0
  5. data/lib/ruby_smb/dcerpc/lsarpc/lsar_close_handle_request.rb +22 -0
  6. data/lib/ruby_smb/dcerpc/lsarpc/lsar_close_handle_response.rb +23 -0
  7. data/lib/ruby_smb/dcerpc/lsarpc/lsar_lookup_sids_request.rb +26 -0
  8. data/lib/ruby_smb/dcerpc/lsarpc/lsar_lookup_sids_response.rb +25 -0
  9. data/lib/ruby_smb/dcerpc/lsarpc/lsar_open_policy2_request.rb +24 -0
  10. data/lib/ruby_smb/dcerpc/lsarpc/lsar_open_policy2_response.rb +23 -0
  11. data/lib/ruby_smb/dcerpc/lsarpc/lsar_open_policy_request.rb +24 -0
  12. data/lib/ruby_smb/dcerpc/lsarpc/lsar_open_policy_response.rb +23 -0
  13. data/lib/ruby_smb/dcerpc/lsarpc/lsar_query_information_policy2_request.rb +23 -0
  14. data/lib/ruby_smb/dcerpc/lsarpc/lsar_query_information_policy2_response.rb +23 -0
  15. data/lib/ruby_smb/dcerpc/lsarpc/lsar_query_information_policy_request.rb +23 -0
  16. data/lib/ruby_smb/dcerpc/lsarpc/lsar_query_information_policy_response.rb +23 -0
  17. data/lib/ruby_smb/dcerpc/lsarpc.rb +634 -2
  18. data/lib/ruby_smb/dcerpc/netlogon/domain_controller_infow.rb +28 -0
  19. data/lib/ruby_smb/dcerpc/netlogon/dsr_get_dc_name_ex2_request.rb +28 -0
  20. data/lib/ruby_smb/dcerpc/netlogon/dsr_get_dc_name_ex2_response.rb +24 -0
  21. data/lib/ruby_smb/dcerpc/netlogon.rb +3 -0
  22. data/lib/ruby_smb/dcerpc/request.rb +8 -0
  23. data/lib/ruby_smb/dcerpc/samr/rpc_sid.rb +1 -1
  24. data/lib/ruby_smb/version.rb +1 -1
  25. data/spec/lib/ruby_smb/dcerpc/lsarpc/lsar_close_handle_request_spec.rb +40 -0
  26. data/spec/lib/ruby_smb/dcerpc/lsarpc/lsar_close_handle_response_spec.rb +46 -0
  27. data/spec/lib/ruby_smb/dcerpc/lsarpc/lsar_lookup_sids_request_spec.rb +69 -0
  28. data/spec/lib/ruby_smb/dcerpc/lsarpc/lsar_lookup_sids_response_spec.rb +56 -0
  29. data/spec/lib/ruby_smb/dcerpc/lsarpc/lsar_open_policy2_request_spec.rb +68 -0
  30. data/spec/lib/ruby_smb/dcerpc/lsarpc/lsar_open_policy2_response_spec.rb +46 -0
  31. data/spec/lib/ruby_smb/dcerpc/lsarpc/lsar_open_policy_request_spec.rb +68 -0
  32. data/spec/lib/ruby_smb/dcerpc/lsarpc/lsar_open_policy_response_spec.rb +45 -0
  33. data/spec/lib/ruby_smb/dcerpc/lsarpc/lsar_query_information_policy2_request_spec.rb +47 -0
  34. data/spec/lib/ruby_smb/dcerpc/lsarpc/lsar_query_information_policy2_response_spec.rb +54 -0
  35. data/spec/lib/ruby_smb/dcerpc/lsarpc/lsar_query_information_policy_request_spec.rb +46 -0
  36. data/spec/lib/ruby_smb/dcerpc/lsarpc/lsar_query_information_policy_response_spec.rb +53 -0
  37. data.tar.gz.sig +0 -0
  38. metadata +42 -3
  39. metadata.gz.sig +0 -0
@@ -0,0 +1,28 @@
1
+ require 'ruby_smb/dcerpc/ndr'
2
+
3
+ module RubySMB
4
+ module Dcerpc
5
+ module Netlogon
6
+
7
+ # [3.5.4.3.1 DsrGetDcNameEx2 (Opnum 34)](https://learn.microsoft.com/en-us/openspecs/windows_protocols/ms-nrpc/fb8e1146-a045-4c31-98d1-c68507ad5620)
8
+ class DsrGetDcNameEx2Request < BinData::Record
9
+ attr_reader :opnum
10
+
11
+ endian :little
12
+
13
+ logonsrv_handle :computer_name
14
+ ndr_wide_stringz_ptr :account_name
15
+ ndr_uint32 :allowable_account_control_bits
16
+ ndr_wide_stringz_ptr :domain_name
17
+ uuid_ptr :domain_guid
18
+ ndr_wide_stringz_ptr :site_name
19
+ ndr_uint32 :flags
20
+
21
+ def initialize_instance
22
+ super
23
+ @opnum = DSR_GET_DC_NAME_EX2
24
+ end
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,24 @@
1
+ require 'ruby_smb/dcerpc/ndr'
2
+ require 'ruby_smb/dcerpc/netlogon/domain_controller_infow'
3
+
4
+ module RubySMB
5
+ module Dcerpc
6
+ module Netlogon
7
+
8
+ # [3.5.4.3.1 DsrGetDcNameEx2 (Opnum 34)](https://learn.microsoft.com/en-us/openspecs/windows_protocols/ms-nrpc/fb8e1146-a045-4c31-98d1-c68507ad5620)
9
+ class DsrGetDcNameEx2Response < BinData::Record
10
+ attr_reader :opnum
11
+
12
+ endian :little
13
+
14
+ domain_controller_info_w_ptr :domain_controller_info
15
+ ndr_uint32 :error_status
16
+
17
+ def initialize_instance
18
+ super
19
+ @opnum = DSR_GET_DC_NAME_EX2
20
+ end
21
+ end
22
+ end
23
+ end
24
+ end
@@ -11,6 +11,7 @@ module RubySMB
11
11
  NETR_SERVER_REQ_CHALLENGE = 4
12
12
  NETR_SERVER_AUTHENTICATE3 = 26
13
13
  NETR_SERVER_PASSWORD_SET2 = 30
14
+ DSR_GET_DC_NAME_EX2 = 34
14
15
 
15
16
  # see: https://docs.microsoft.com/en-us/openspecs/windows_protocols/ms-nrpc/3b224201-b531-43e2-8c79-b61f6dea8640
16
17
  class LogonsrvHandle < Ndr::NdrWideStringzPtr; end
@@ -65,6 +66,8 @@ module RubySMB
65
66
  require 'ruby_smb/dcerpc/netlogon/netr_server_password_set2_response'
66
67
  require 'ruby_smb/dcerpc/netlogon/netr_server_req_challenge_request'
67
68
  require 'ruby_smb/dcerpc/netlogon/netr_server_req_challenge_response'
69
+ require 'ruby_smb/dcerpc/netlogon/dsr_get_dc_name_ex2_request'
70
+ require 'ruby_smb/dcerpc/netlogon/dsr_get_dc_name_ex2_response'
68
71
 
69
72
  # Calculate the netlogon session key from the provided shared secret and
70
73
  # challenges. The shared secret is an NTLM hash.
@@ -111,6 +111,14 @@ module RubySMB
111
111
  efs_rpc_query_recovery_agents_request Efsrpc::EFS_RPC_QUERY_RECOVERY_AGENTS
112
112
  efs_rpc_query_users_on_file_request Efsrpc::EFS_RPC_QUERY_USERS_ON_FILE
113
113
  end
114
+ choice 'Lsarpc', selection: -> { opnum } do
115
+ lsar_open_policy_request Lsarpc::LSAR_OPEN_POLICY
116
+ lsar_open_policy2_request Lsarpc::LSAR_OPEN_POLICY2
117
+ lsar_query_information_policy_request Lsarpc::LSAR_QUERY_INFORMATION_POLICY
118
+ lsar_query_information_policy2_request Lsarpc::LSAR_QUERY_INFORMATION_POLICY2
119
+ lsar_close_handle_request Lsarpc::LSAR_CLOSE_HANDLE
120
+ lsar_lookup_sids_request Lsarpc::LSAR_LOOKUP_SIDS
121
+ end
114
122
  string :default
115
123
  end
116
124
 
@@ -107,7 +107,7 @@ module RubySMB
107
107
  case val
108
108
  when String
109
109
  elems = val.split('-')
110
- raise ArgumentError, "Wrong SID format" unless elems[0].downcase == 's'
110
+ raise ArgumentError, "Wrong SID format for #{val.inspect}" unless elems[0].downcase == 's'
111
111
  self.revision = elems[1].to_i
112
112
  self.sub_authority_count = elems[3..-1].size
113
113
  self.identifier_authority = [0, 0, 0, 0, 0, elems[2].to_i]
@@ -1,3 +1,3 @@
1
1
  module RubySMB
2
- VERSION = '3.3.7'.freeze
2
+ VERSION = '3.3.9'.freeze
3
3
  end
@@ -0,0 +1,40 @@
1
+ RSpec.describe RubySMB::Dcerpc::Lsarpc::LsarCloseHandleRequest do
2
+ subject(:packet) { described_class.new }
3
+
4
+ it { is_expected.to respond_to :policy_handle }
5
+ it { is_expected.to respond_to :opnum }
6
+
7
+ it 'is little endian' do
8
+ expect(described_class.fields.instance_variable_get(:@hints)[:endian]).to eq :little
9
+ end
10
+ it 'is a BinData::Record' do
11
+ expect(packet).to be_a(BinData::Record)
12
+ end
13
+ describe '#policy_handle' do
14
+ it 'is an LsaprHandle structure' do
15
+ expect(packet.policy_handle).to be_a RubySMB::Dcerpc::Lsarpc::LsaprHandle
16
+ end
17
+ end
18
+ describe '#initialize_instance' do
19
+ it 'sets #opnum to LSAR_CLOSE_HANDLE constant' do
20
+ expect(packet.opnum).to eq(RubySMB::Dcerpc::Lsarpc::LSAR_CLOSE_HANDLE)
21
+ end
22
+ end
23
+ it 'reads itself' do
24
+ new_packet = described_class.new(
25
+ policy_handle: {
26
+ context_handle_attributes: 0,
27
+ context_handle_uuid: "fc873b90-d9a9-46a4-b9ea-f44bb1c272a7"
28
+ }
29
+ )
30
+ expected_output = {
31
+ policy_handle: {
32
+ context_handle_attributes: 0,
33
+ context_handle_uuid: "fc873b90-d9a9-46a4-b9ea-f44bb1c272a7"
34
+ }
35
+ }
36
+ expect(packet.read(new_packet.to_binary_s)).to eq(expected_output)
37
+ end
38
+ end
39
+
40
+
@@ -0,0 +1,46 @@
1
+ RSpec.describe RubySMB::Dcerpc::Lsarpc::LsarCloseHandleResponse do
2
+ subject(:packet) { described_class.new }
3
+
4
+ it { is_expected.to respond_to :policy_handle }
5
+ it { is_expected.to respond_to :error_status }
6
+ it { is_expected.to respond_to :opnum }
7
+
8
+ it 'is little endian' do
9
+ expect(described_class.fields.instance_variable_get(:@hints)[:endian]).to eq :little
10
+ end
11
+ it 'is a BinData::Record' do
12
+ expect(packet).to be_a(BinData::Record)
13
+ end
14
+ describe '#policy_handle' do
15
+ it 'is a LsaprHandle structure' do
16
+ expect(packet.policy_handle).to be_a RubySMB::Dcerpc::Lsarpc::LsaprHandle
17
+ end
18
+ end
19
+ describe '#error_status' do
20
+ it 'is a NdrUint32 structure' do
21
+ expect(packet.error_status).to be_a RubySMB::Dcerpc::Ndr::NdrUint32
22
+ end
23
+ end
24
+ describe '#initialize_instance' do
25
+ it 'sets #opnum to LSAR_CLOSE_HANDLE constant' do
26
+ expect(packet.opnum).to eq(RubySMB::Dcerpc::Lsarpc::LSAR_CLOSE_HANDLE)
27
+ end
28
+ end
29
+ it 'reads itself' do
30
+ new_class = described_class.new(
31
+ policy_handle: {
32
+ context_handle_attributes: 0,
33
+ context_handle_uuid: '2ef54a87-e29e-4d24-90e9-9da49b94449e'
34
+ },
35
+ error_status: 0
36
+ )
37
+ expect(packet.read(new_class.to_binary_s)).to eq(
38
+ {
39
+ policy_handle: {
40
+ context_handle_attributes: 0,
41
+ context_handle_uuid: '2ef54a87-e29e-4d24-90e9-9da49b94449e'
42
+ },
43
+ error_status: 0
44
+ })
45
+ end
46
+ end
@@ -0,0 +1,69 @@
1
+ require 'ruby_smb/dcerpc/ndr'
2
+
3
+ RSpec.describe RubySMB::Dcerpc::Lsarpc::LsarLookupSidsRequest do
4
+ subject(:packet) { described_class.new }
5
+
6
+ it { is_expected.to respond_to :policy_handle }
7
+ it { is_expected.to respond_to :sid_enum_buffer }
8
+ it { is_expected.to respond_to :translated_names }
9
+ it { is_expected.to respond_to :lookup_level }
10
+ it { is_expected.to respond_to :mapped_count }
11
+ it { is_expected.to respond_to :opnum }
12
+
13
+ it 'is little endian' do
14
+ expect(described_class.fields.instance_variable_get(:@hints)[:endian]).to eq :little
15
+ end
16
+ it 'is a BinData::Record' do
17
+ expect(packet).to be_a(BinData::Record)
18
+ end
19
+ describe '#policy_handle' do
20
+ it 'is an LsaprHandle structure' do
21
+ expect(packet.policy_handle).to be_a RubySMB::Dcerpc::Lsarpc::LsaprHandle
22
+ end
23
+ end
24
+ describe '#sid_enum_buffer' do
25
+ it 'is an LsaprSidEnumBuffer structure' do
26
+ expect(packet.sid_enum_buffer).to be_a RubySMB::Dcerpc::Lsarpc::LsaprSidEnumBuffer
27
+ end
28
+ end
29
+ describe '#translated_names' do
30
+ it 'is an LsaprTranslatedNames structure' do
31
+ expect(packet.translated_names).to be_a RubySMB::Dcerpc::Lsarpc::LsaprTranslatedNames
32
+ end
33
+ end
34
+ describe '#lookup_level' do
35
+ it 'is an NdrUint16' do
36
+ expect(packet.lookup_level).to be_a RubySMB::Dcerpc::Ndr::NdrUint16
37
+ end
38
+ end
39
+ describe '#mapped_count' do
40
+ it 'is an NdrUint32' do
41
+ expect(packet.mapped_count).to be_a RubySMB::Dcerpc::Ndr::NdrUint32
42
+ end
43
+ end
44
+ describe '#initialize_instance' do
45
+ it 'sets #opnum to LSAR_LOOKUP_SIDS constant' do
46
+ expect(packet.opnum).to eq(RubySMB::Dcerpc::Lsarpc::LSAR_LOOKUP_SIDS)
47
+ end
48
+ end
49
+ it 'reads itself' do
50
+ new_class = described_class.new(
51
+ policy_handle: {
52
+ context_handle_attributes: 0,
53
+ context_handle_uuid: "fc873b90-d9a9-46a4-b9ea-f44bb1c272a7"
54
+ },
55
+ sid_enum_buffer: { num_entries: 1, sid_info: [ { sid: 'S-1-5-21-2181772609-2124839192-2039643012-500' } ] },
56
+ lookup_level: 0,
57
+ )
58
+ expect(packet.read(new_class.to_binary_s)).to eq(
59
+ policy_handle: {
60
+ context_handle_attributes: 0,
61
+ context_handle_uuid: "fc873b90-d9a9-46a4-b9ea-f44bb1c272a7"
62
+ },
63
+ sid_enum_buffer: { num_entries: 1, sid_info: [ { sid: 'S-1-5-21-2181772609-2124839192-2039643012-500' } ] },
64
+ translated_names: { num_entries: 0, names: :null },
65
+ lookup_level: 0,
66
+ mapped_count: 0
67
+ )
68
+ end
69
+ end
@@ -0,0 +1,56 @@
1
+ require 'ruby_smb/dcerpc/ndr'
2
+
3
+ RSpec.describe RubySMB::Dcerpc::Lsarpc::LsarLookupSidsResponse do
4
+ subject(:packet) { described_class.new }
5
+
6
+ it { is_expected.to respond_to :referenced_domains }
7
+ it { is_expected.to respond_to :translated_names }
8
+ it { is_expected.to respond_to :mapped_count }
9
+ it { is_expected.to respond_to :error_status }
10
+ it { is_expected.to respond_to :opnum }
11
+
12
+ it 'is little endian' do
13
+ expect(described_class.fields.instance_variable_get(:@hints)[:endian]).to eq :little
14
+ end
15
+ it 'is a BinData::Record' do
16
+ expect(packet).to be_a(BinData::Record)
17
+ end
18
+ describe '#referenced_domains' do
19
+ it 'is an LsaprReferencedDomainListPtr structure' do
20
+ expect(packet.referenced_domains).to be_a RubySMB::Dcerpc::Lsarpc::LsaprReferencedDomainListPtr
21
+ end
22
+ end
23
+ describe '#translated_names' do
24
+ it 'is an LsaprTranslatedNames structure' do
25
+ expect(packet.translated_names).to be_a RubySMB::Dcerpc::Lsarpc::LsaprTranslatedNames
26
+ end
27
+ end
28
+ describe '#mapped_count' do
29
+ it 'is an NdrUint32 structure' do
30
+ expect(packet.mapped_count).to be_a RubySMB::Dcerpc::Ndr::NdrUint32
31
+ end
32
+ end
33
+ describe '#error_status' do
34
+ it 'is an NdrUint32' do
35
+ expect(packet.error_status).to be_a RubySMB::Dcerpc::Ndr::NdrUint32
36
+ end
37
+ end
38
+ describe '#initialize_instance' do
39
+ it 'sets #opnum to LSAR_LOOKUP_SIDS constant' do
40
+ expect(packet.opnum).to eq(RubySMB::Dcerpc::Lsarpc::LSAR_LOOKUP_SIDS)
41
+ end
42
+ end
43
+ it 'reads itself' do
44
+ new_class = described_class.new(
45
+ translated_names: { num_entries: 1, names: [ { use: 0, name: 'Administrator', domain_index: 0 }] },
46
+ mapped_count: 1,
47
+ error_status: 0
48
+ )
49
+ expect(packet.read(new_class.to_binary_s)).to eq(
50
+ referenced_domains: :null,
51
+ translated_names: { num_entries: 1, names: [ { use: 0, name: { buffer_length: 26, maximum_length: 26, buffer: 'Administrator'.encode('UTF-16LE') }, domain_index: 0 } ] },
52
+ mapped_count: 1,
53
+ error_status: 0
54
+ )
55
+ end
56
+ end
@@ -0,0 +1,68 @@
1
+ require 'ruby_smb/dcerpc/ndr'
2
+
3
+ RSpec.describe RubySMB::Dcerpc::Lsarpc::LsarOpenPolicy2Request do
4
+ subject(:packet) { described_class.new }
5
+
6
+ it { is_expected.to respond_to :system_name }
7
+ it { is_expected.to respond_to :object_attributes }
8
+ it { is_expected.to respond_to :access_mask }
9
+ it { is_expected.to respond_to :opnum }
10
+
11
+ it 'is little endian' do
12
+ expect(described_class.fields.instance_variable_get(:@hints)[:endian]).to eq :little
13
+ end
14
+ it 'is a BinData::Record' do
15
+ expect(packet).to be_a(BinData::Record)
16
+ end
17
+ describe '#system_name' do
18
+ it 'is an NdrWideStringzPtr structure' do
19
+ expect(packet.system_name).to be_a RubySMB::Dcerpc::Ndr::NdrWideStringzPtr
20
+ end
21
+ end
22
+ describe '#object_attributes' do
23
+ it 'is an LsaprObjectAttributes structure' do
24
+ expect(packet.object_attributes).to be_a RubySMB::Dcerpc::Lsarpc::LsaprObjectAttributes
25
+ end
26
+ end
27
+ describe '#access_mask' do
28
+ it 'is an NdrUint32 structure' do
29
+ expect(packet.access_mask).to be_a RubySMB::Dcerpc::Ndr::NdrUint32
30
+ end
31
+ end
32
+ describe '#initialize_instance' do
33
+ it 'sets #opnum to LSAR_OPEN_POLICY2 constant' do
34
+ expect(packet.opnum).to eq(RubySMB::Dcerpc::Lsarpc::LSAR_OPEN_POLICY2)
35
+ end
36
+ end
37
+ it 'reads itself' do
38
+ new_class = described_class.new(
39
+ system_name: 'Example_System',
40
+ object_attributes: {
41
+ security_quality_of_service: {
42
+ impersonation_level: 0,
43
+ security_context_tracking_mode: 0
44
+ }
45
+ },
46
+ access_mask: 0
47
+ )
48
+ expect(packet.read(new_class.to_binary_s)).to eq(
49
+ {
50
+ system_name: 'Example_System'.encode('UTF-16LE'),
51
+ object_attributes: {
52
+ len: 24,
53
+ root_directory: :null,
54
+ object_name: :null,
55
+ attributes: 0,
56
+ security_descriptor: :null,
57
+ security_quality_of_service: {
58
+ len: 12,
59
+ impersonation_level: 0,
60
+ security_context_tracking_mode: 0,
61
+ effective_only: 0
62
+ }
63
+ },
64
+ access_mask: 0
65
+ }
66
+ )
67
+ end
68
+ end
@@ -0,0 +1,46 @@
1
+
2
+ RSpec.describe RubySMB::Dcerpc::Lsarpc::LsarOpenPolicy2Response do
3
+ subject(:packet) { described_class.new }
4
+
5
+ it { is_expected.to respond_to :policy_handle }
6
+ it { is_expected.to respond_to :error_status }
7
+ it { is_expected.to respond_to :opnum }
8
+
9
+ it 'is little endian' do
10
+ expect(described_class.fields.instance_variable_get(:@hints)[:endian]).to eq :little
11
+ end
12
+ it 'is a BinData::Record' do
13
+ expect(packet).to be_a(BinData::Record)
14
+ end
15
+ describe '#policy_handle' do
16
+ it 'is an LsaprHandle structure' do
17
+ expect(packet.policy_handle).to be_a RubySMB::Dcerpc::Lsarpc::LsaprHandle
18
+ end
19
+ end
20
+ describe '#error_status' do
21
+ it 'is a NdrUint32' do
22
+ expect(packet.error_status).to be_a RubySMB::Dcerpc::Ndr::NdrUint32
23
+ end
24
+ end
25
+ describe '#initialize_instance' do
26
+ it 'sets #opnum to LSAR_OPEN_POLICY2 constant' do
27
+ expect(packet.opnum).to eq(RubySMB::Dcerpc::Lsarpc::LSAR_OPEN_POLICY2)
28
+ end
29
+ end
30
+ it 'reads itself' do
31
+ new_class = described_class.new(
32
+ policy_handle: {
33
+ context_handle_attributes: 0,
34
+ context_handle_uuid: "fc873b90-d9a9-46a4-b9ea-f44bb1c272a7"
35
+ },
36
+ error_status: 0
37
+ )
38
+ expect(packet.read(new_class.to_binary_s)).to eq(
39
+ policy_handle: {
40
+ context_handle_attributes: 0,
41
+ context_handle_uuid: "fc873b90-d9a9-46a4-b9ea-f44bb1c272a7"
42
+ },
43
+ error_status: 0
44
+ )
45
+ end
46
+ end
@@ -0,0 +1,68 @@
1
+ require 'ruby_smb/dcerpc/ndr'
2
+
3
+ RSpec.describe RubySMB::Dcerpc::Lsarpc::LsarOpenPolicyRequest do
4
+ subject(:packet) { described_class.new }
5
+
6
+ it { is_expected.to respond_to :system_name }
7
+ it { is_expected.to respond_to :object_attributes }
8
+ it { is_expected.to respond_to :access_mask }
9
+ it { is_expected.to respond_to :opnum }
10
+
11
+ it 'is little endian' do
12
+ expect(described_class.fields.instance_variable_get(:@hints)[:endian]).to eq :little
13
+ end
14
+ it 'is a BinData::Record' do
15
+ expect(packet).to be_a(BinData::Record)
16
+ end
17
+ describe '#system_name' do
18
+ it 'is an NdrWideStringPtr structure' do
19
+ expect(packet.system_name).to be_a RubySMB::Dcerpc::Ndr::NdrWideStringPtr
20
+ end
21
+ end
22
+ describe '#object_attributes' do
23
+ it 'is an LsaprObjectAttributes structure' do
24
+ expect(packet.object_attributes).to be_a RubySMB::Dcerpc::Lsarpc::LsaprObjectAttributes
25
+ end
26
+ end
27
+ describe '#access_mask' do
28
+ it 'is an NdrUint32 structure' do
29
+ expect(packet.access_mask).to be_a RubySMB::Dcerpc::Ndr::NdrUint32
30
+ end
31
+ end
32
+ describe '#initialize_instance' do
33
+ it 'sets #opnum to LSAR_OPEN_POLICY constant' do
34
+ expect(packet.opnum).to eq(RubySMB::Dcerpc::Lsarpc::LSAR_OPEN_POLICY)
35
+ end
36
+ end
37
+ it 'reads itself' do
38
+ new_class = described_class.new(
39
+ system_name: 'Example_System',
40
+ object_attributes: {
41
+ security_quality_of_service: {
42
+ impersonation_level: 0,
43
+ security_context_tracking_mode: 0
44
+ }
45
+ },
46
+ access_mask: 0
47
+ )
48
+ expect(packet.read(new_class.to_binary_s)).to eq(
49
+ {
50
+ system_name: 'Example_System'.encode('UTF-16LE'),
51
+ object_attributes: {
52
+ len: 24,
53
+ root_directory: :null,
54
+ object_name: :null,
55
+ attributes: 0,
56
+ security_descriptor: :null,
57
+ security_quality_of_service: {
58
+ len: 12,
59
+ impersonation_level: 0,
60
+ security_context_tracking_mode: 0,
61
+ effective_only: 0
62
+ }
63
+ },
64
+ access_mask: 0
65
+ }
66
+ )
67
+ end
68
+ end
@@ -0,0 +1,45 @@
1
+
2
+ RSpec.describe RubySMB::Dcerpc::Lsarpc::LsarOpenPolicyResponse do
3
+ subject(:packet) { described_class.new }
4
+
5
+ it { is_expected.to respond_to :policy_handle }
6
+ it { is_expected.to respond_to :error_status }
7
+ it { is_expected.to respond_to :opnum }
8
+
9
+ it 'is little endian' do
10
+ expect(described_class.fields.instance_variable_get(:@hints)[:endian]).to eq :little
11
+ end
12
+ it 'is a BinData::Record' do
13
+ expect(packet).to be_a(BinData::Record)
14
+ end
15
+ describe '#policy_handle' do
16
+ it 'is an LsaprHandle structure' do
17
+ expect(packet.policy_handle).to be_a RubySMB::Dcerpc::Lsarpc::LsaprHandle
18
+ end
19
+ end
20
+ describe '#error_status' do
21
+ it 'is a NdrUint32' do
22
+ expect(packet.error_status).to be_a RubySMB::Dcerpc::Ndr::NdrUint32
23
+ end
24
+ end
25
+ describe '#initialize_instance' do
26
+ it 'sets #opnum to LSAR_OPEN_POLICY constant' do
27
+ expect(packet.opnum).to eq(RubySMB::Dcerpc::Lsarpc::LSAR_OPEN_POLICY)
28
+ end
29
+ end
30
+ it 'reads itself' do
31
+ new_class = described_class.new(
32
+ policy_handle: {
33
+ context_handle_attributes: 0,
34
+ context_handle_uuid: "fc873b90-d9a9-46a4-b9ea-f44bb1c272a7"
35
+ }
36
+ )
37
+ expect(packet.read(new_class.to_binary_s)).to eq(
38
+ policy_handle: {
39
+ context_handle_attributes: 0,
40
+ context_handle_uuid: "fc873b90-d9a9-46a4-b9ea-f44bb1c272a7"
41
+ },
42
+ error_status: 0
43
+ )
44
+ end
45
+ end
@@ -0,0 +1,47 @@
1
+ require 'ruby_smb/dcerpc/ndr'
2
+
3
+ RSpec.describe RubySMB::Dcerpc::Lsarpc::LsarQueryInformationPolicy2Request do
4
+ subject(:packet) { described_class.new }
5
+
6
+ it { is_expected.to respond_to :policy_handle }
7
+ it { is_expected.to respond_to :information_class }
8
+ it { is_expected.to respond_to :opnum }
9
+
10
+ it 'is little endian' do
11
+ expect(described_class.fields.instance_variable_get(:@hints)[:endian]).to eq :little
12
+ end
13
+ it 'is a BinData::Record' do
14
+ expect(packet).to be_a(BinData::Record)
15
+ end
16
+ describe '#policy_handle' do
17
+ it 'is an LsaprHandle structure' do
18
+ expect(packet.policy_handle).to be_a RubySMB::Dcerpc::Lsarpc::LsaprHandle
19
+ end
20
+ end
21
+ describe '#information_class' do
22
+ it 'is an NdrUint32 structure' do
23
+ expect(packet.information_class).to be_a RubySMB::Dcerpc::Ndr::NdrUint32
24
+ end
25
+ end
26
+ describe '#initialize_instance' do
27
+ it 'sets #opnum to LSAR_QUERY_INFORMATION_POLICY2 constant' do
28
+ expect(packet.opnum).to eq(RubySMB::Dcerpc::Lsarpc::LSAR_QUERY_INFORMATION_POLICY2)
29
+ end
30
+ end
31
+ it 'reads itself' do
32
+ new_class = described_class.new(
33
+ policy_handle: {
34
+ context_handle_attributes: 0,
35
+ context_handle_uuid: "fc873b90-d9a9-46a4-b9ea-f44bb1c272a7"
36
+ },
37
+ information_class: 0
38
+ )
39
+ expect(packet.read(new_class.to_binary_s)).to eq(
40
+ policy_handle: {
41
+ context_handle_attributes: 0,
42
+ context_handle_uuid: "fc873b90-d9a9-46a4-b9ea-f44bb1c272a7"
43
+ },
44
+ information_class: 0
45
+ )
46
+ end
47
+ end
@@ -0,0 +1,54 @@
1
+ require 'ruby_smb/dcerpc/ndr'
2
+ require 'ruby_smb/dcerpc/lsarpc'
3
+
4
+ RSpec.describe RubySMB::Dcerpc::Lsarpc::LsarQueryInformationPolicy2Response do
5
+ subject(:packet) { described_class.new }
6
+
7
+ it { is_expected.to respond_to :policy_information }
8
+ it { is_expected.to respond_to :error_status }
9
+ it { is_expected.to respond_to :opnum }
10
+
11
+ it 'is little endian' do
12
+ expect(described_class.fields.instance_variable_get(:@hints)[:endian]).to eq :little
13
+ end
14
+ it 'is a BinData::Record' do
15
+ expect(packet).to be_a(BinData::Record)
16
+ end
17
+ describe '#policy_information' do
18
+ it 'is an LsaprPolicyInformationPtr structure' do
19
+ expect(packet.policy_information).to be_a RubySMB::Dcerpc::Lsarpc::LsaprPolicyInformationPtr
20
+ end
21
+ end
22
+ describe '#error_status' do
23
+ it 'is an NdrUint32 structure' do
24
+ expect(packet.error_status).to be_a RubySMB::Dcerpc::Ndr::NdrUint32
25
+ end
26
+ end
27
+ describe '#initialize_instance' do
28
+ it 'sets #opnum to LSAR_QUERY_INFORMATION_POLICY2 constant' do
29
+ expect(packet.opnum).to eq(RubySMB::Dcerpc::Lsarpc::LSAR_QUERY_INFORMATION_POLICY2)
30
+ end
31
+ end
32
+ it 'reads itself' do
33
+ new_class = described_class.new(
34
+ policy_information: {
35
+ policy_information_class: 1,
36
+ policy_information: {}
37
+ }
38
+ )
39
+ expect(packet.read(new_class.to_binary_s)).to eq(
40
+ policy_information: {
41
+ policy_information_class: 1,
42
+ policy_information: {
43
+ audit_log_percent_full: 0,
44
+ maximum_log_size: 0,
45
+ audit_retention_period: 0,
46
+ audit_log_full_shutdown_in_progress: 0,
47
+ time_to_shutdown: 0,
48
+ next_audit_record_id: 0
49
+ }
50
+ },
51
+ error_status: 0
52
+ )
53
+ end
54
+ end