ruby_smb 3.1.3 → 3.1.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (55) hide show
  1. checksums.yaml +4 -4
  2. checksums.yaml.gz.sig +0 -0
  3. data/lib/ruby_smb/client/authentication.rb +29 -4
  4. data/lib/ruby_smb/client/negotiation.rb +2 -0
  5. data/lib/ruby_smb/client.rb +16 -1
  6. data/lib/ruby_smb/dcerpc/dfsnm/netr_dfs_add_std_root_request.rb +24 -0
  7. data/lib/ruby_smb/dcerpc/dfsnm/netr_dfs_add_std_root_response.rb +21 -0
  8. data/lib/ruby_smb/dcerpc/dfsnm/netr_dfs_remove_std_root_request.rb +23 -0
  9. data/lib/ruby_smb/dcerpc/dfsnm/netr_dfs_remove_std_root_response.rb +21 -0
  10. data/lib/ruby_smb/dcerpc/dfsnm.rb +84 -0
  11. data/lib/ruby_smb/dcerpc/error.rb +24 -0
  12. data/lib/ruby_smb/dcerpc/fault.rb +83 -0
  13. data/lib/ruby_smb/dcerpc/ndr.rb +19 -8
  14. data/lib/ruby_smb/dcerpc/request.rb +21 -11
  15. data/lib/ruby_smb/dcerpc/rrp_rpc_unicode_string.rb +5 -0
  16. data/lib/ruby_smb/dcerpc/samr/samr_create_user2_in_domain_request.rb +24 -0
  17. data/lib/ruby_smb/dcerpc/samr/samr_create_user2_in_domain_response.rb +24 -0
  18. data/lib/ruby_smb/dcerpc/samr/samr_delete_user_request.rb +21 -0
  19. data/lib/ruby_smb/dcerpc/samr/samr_delete_user_response.rb +22 -0
  20. data/lib/ruby_smb/dcerpc/samr/samr_enumerate_domains_in_sam_server_request.rb +25 -0
  21. data/lib/ruby_smb/dcerpc/samr/samr_enumerate_domains_in_sam_server_response.rb +25 -0
  22. data/lib/ruby_smb/dcerpc/samr/samr_enumerate_users_in_domain_response.rb +0 -31
  23. data/lib/ruby_smb/dcerpc/samr/samr_get_alias_membership_response.rb +1 -14
  24. data/lib/ruby_smb/dcerpc/samr/samr_lookup_names_in_domain_request.rb +23 -0
  25. data/lib/ruby_smb/dcerpc/samr/samr_lookup_names_in_domain_response.rb +23 -0
  26. data/lib/ruby_smb/dcerpc/samr/samr_set_information_user2_request.rb +23 -0
  27. data/lib/ruby_smb/dcerpc/samr/samr_set_information_user2_response.rb +21 -0
  28. data/lib/ruby_smb/dcerpc/samr.rb +453 -83
  29. data/lib/ruby_smb/dcerpc.rb +2 -0
  30. data/lib/ruby_smb/error.rb +25 -11
  31. data/lib/ruby_smb/gss.rb +1 -0
  32. data/lib/ruby_smb/smb1/packet/session_setup_request.rb +11 -0
  33. data/lib/ruby_smb/smb1/pipe.rb +6 -1
  34. data/lib/ruby_smb/smb2/pipe.rb +6 -2
  35. data/lib/ruby_smb/version.rb +1 -1
  36. data/spec/lib/ruby_smb/client_spec.rb +1 -0
  37. data/spec/lib/ruby_smb/dcerpc/dfsnm/netr_dfs_add_std_root_request_spec.rb +57 -0
  38. data/spec/lib/ruby_smb/dcerpc/dfsnm/netr_dfs_add_std_root_response_spec.rb +34 -0
  39. data/spec/lib/ruby_smb/dcerpc/dfsnm/netr_dfs_remove_std_root_request_spec.rb +49 -0
  40. data/spec/lib/ruby_smb/dcerpc/dfsnm/netr_dfs_remove_std_root_response_spec.rb +34 -0
  41. data/spec/lib/ruby_smb/dcerpc/samr/samr_create_user2_in_domain_request_spec.rb +69 -0
  42. data/spec/lib/ruby_smb/dcerpc/samr/samr_create_user2_in_domain_response_spec.rb +69 -0
  43. data/spec/lib/ruby_smb/dcerpc/samr/samr_delete_user_request_spec.rb +42 -0
  44. data/spec/lib/ruby_smb/dcerpc/samr/samr_delete_user_response_spec.rb +51 -0
  45. data/spec/lib/ruby_smb/dcerpc/samr/samr_enumerate_domains_in_sam_server_request_spec.rb +60 -0
  46. data/spec/lib/ruby_smb/dcerpc/samr/samr_enumerate_domains_in_sam_server_response_spec.rb +75 -0
  47. data/spec/lib/ruby_smb/dcerpc/samr/samr_enumerate_users_in_domain_response_spec.rb +0 -195
  48. data/spec/lib/ruby_smb/dcerpc/samr/samr_lookup_names_in_domain_request_spec.rb +62 -0
  49. data/spec/lib/ruby_smb/dcerpc/samr/samr_lookup_names_in_domain_response_spec.rb +54 -0
  50. data/spec/lib/ruby_smb/dcerpc/samr/samr_set_information_user2_request_spec.rb +67 -0
  51. data/spec/lib/ruby_smb/dcerpc/samr/samr_set_information_user2_response_spec.rb +35 -0
  52. data/spec/lib/ruby_smb/dcerpc/samr_spec.rb +194 -0
  53. data.tar.gz.sig +2 -2
  54. metadata +46 -2
  55. metadata.gz.sig +0 -0
data/lib/ruby_smb/gss.rb CHANGED
@@ -14,6 +14,7 @@ module RubySMB
14
14
  # @param asn The ASN object to apply the traversal path on.
15
15
  # @param [Array] path The path to traverse, each element is passed to the
16
16
  # ASN object's #value's #[] operator.
17
+ # @return [OpenSSL::ASN1::Sequence, nil]
17
18
  def self.asn1dig(asn, *path)
18
19
  path.each do |part|
19
20
  return nil unless asn&.value
@@ -40,6 +40,17 @@ module RubySMB
40
40
  parameter_block :parameter_block
41
41
  data_block :data_block
42
42
 
43
+ # Takes the specified security buffer string and sets it in the {RubySMB::SMB1::Packet::SessionSetupRequest::DataBlock#security_blob}
44
+ # field. It also automatically sets the length in
45
+ # {RubySMB::SMB1::Packet::SessionSetupRequest::ParameterBlock#security_blob_length}
46
+ #
47
+ # @param buffer [String] the security buffer
48
+ # @return [void]
49
+ def set_security_buffer(buffer)
50
+ parameter_block.security_blob_length = buffer.length
51
+ data_block.security_blob = buffer
52
+ end
53
+
43
54
  # Takes an NTLM Type 1 Message and creates the GSS Security Blob
44
55
  # for it and sets it in the {RubySMB::SMB1::Packet::SessionSetupRequest::DataBlock#security_blob}
45
56
  # field. It also automatically sets the length in
@@ -28,6 +28,8 @@ module RubySMB
28
28
  extend RubySMB::Dcerpc::Samr
29
29
  when 'wkssvc', '\\wkssvc'
30
30
  extend RubySMB::Dcerpc::Wkssvc
31
+ when 'netdfs', '\\netdfs'
32
+ extend RubySMB::Dcerpc::Dfsnm
31
33
  end
32
34
  super(tree: tree, response: response, name: name)
33
35
  end
@@ -142,7 +144,10 @@ module RubySMB
142
144
 
143
145
  def dcerpc_response_from_raw_response(raw_data)
144
146
  dcerpc_response = RubySMB::Dcerpc::Response.read(raw_data)
145
- unless dcerpc_response.pdu_header.ptype == RubySMB::Dcerpc::PTypes::RESPONSE
147
+ if dcerpc_response.pdu_header.ptype == RubySMB::Dcerpc::PTypes::FAULT
148
+ status = dcerpc_response.stub.unpack('V').first
149
+ raise RubySMB::Dcerpc::Error::FaultError.new('A fault occurred', status: status)
150
+ elsif dcerpc_response.pdu_header.ptype != RubySMB::Dcerpc::PTypes::RESPONSE
146
151
  raise RubySMB::Dcerpc::Error::InvalidPacket, "Not a Response packet"
147
152
  end
148
153
  dcerpc_response
@@ -25,6 +25,8 @@ module RubySMB
25
25
  extend RubySMB::Dcerpc::Samr
26
26
  when 'wkssvc', '\\wkssvc'
27
27
  extend RubySMB::Dcerpc::Wkssvc
28
+ when 'netdfs', '\\netdfs'
29
+ extend RubySMB::Dcerpc::Dfsnm
28
30
  end
29
31
  super(tree: tree, response: response, name: name)
30
32
  end
@@ -135,12 +137,14 @@ module RubySMB
135
137
  end
136
138
  end
137
139
 
138
-
139
140
  private
140
141
 
141
142
  def dcerpc_response_from_raw_response(raw_data)
142
143
  dcerpc_response = RubySMB::Dcerpc::Response.read(raw_data)
143
- unless dcerpc_response.pdu_header.ptype == RubySMB::Dcerpc::PTypes::RESPONSE
144
+ if dcerpc_response.pdu_header.ptype == RubySMB::Dcerpc::PTypes::FAULT
145
+ status = dcerpc_response.stub.unpack('V').first
146
+ raise RubySMB::Dcerpc::Error::FaultError.new('A fault occurred', status: status)
147
+ elsif dcerpc_response.pdu_header.ptype != RubySMB::Dcerpc::PTypes::RESPONSE
144
148
  raise RubySMB::Dcerpc::Error::InvalidPacket, "Not a Response packet"
145
149
  end
146
150
  dcerpc_response
@@ -1,3 +1,3 @@
1
1
  module RubySMB
2
- VERSION = '3.1.3'.freeze
2
+ VERSION = '3.1.6'.freeze
3
3
  end
@@ -1881,6 +1881,7 @@ RSpec.describe RubySMB::Client do
1881
1881
  before :example do
1882
1882
  smb2_client.smb3 = true
1883
1883
  smb2_client.session_encrypt_data = false
1884
+ smb2_client.preauth_integrity_hash_value = ''
1884
1885
  end
1885
1886
 
1886
1887
  it 'sets the session_encrypt_data parameter to true if the server requires encryption' do
@@ -0,0 +1,57 @@
1
+ RSpec.describe RubySMB::Dcerpc::Dfsnm::NetrDfsAddStdRootRequest do
2
+ subject(:packet) { described_class.new }
3
+
4
+ it { is_expected.to respond_to :server_name }
5
+ it { is_expected.to respond_to :root_share }
6
+ it { is_expected.to respond_to :comment }
7
+ it { is_expected.to respond_to :api_flags }
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 '#server_name' do
17
+ it 'is a NdrConfVarWideStringz structure' do
18
+ expect(packet.server_name).to be_a RubySMB::Dcerpc::Ndr::NdrConfVarWideStringz
19
+ end
20
+ end
21
+ describe '#root_share' do
22
+ it 'is a NdrConfVarWideStringz structure' do
23
+ expect(packet.root_share).to be_a RubySMB::Dcerpc::Ndr::NdrConfVarWideStringz
24
+ end
25
+ end
26
+ describe '#comment' do
27
+ it 'is a NdrConfVarWideStringz structure' do
28
+ expect(packet.comment).to be_a RubySMB::Dcerpc::Ndr::NdrConfVarWideStringz
29
+ end
30
+ end
31
+ describe '#api_flags' do
32
+ it 'is a NdrUint32 structure' do
33
+ expect(packet.api_flags).to be_a RubySMB::Dcerpc::Ndr::NdrUint32
34
+ end
35
+ end
36
+ describe '#initialize_instance' do
37
+ it 'sets #opnum to NETR_DFS_ADD_STD_ROOT constant' do
38
+ expect(packet.opnum).to eq(RubySMB::Dcerpc::Dfsnm::NETR_DFS_ADD_STD_ROOT)
39
+ end
40
+ end
41
+ it 'reads itself' do
42
+ new_packet = described_class.new({
43
+ server_name: 'serverName',
44
+ root_share: 'rootShare',
45
+ comment: 'comment'
46
+ })
47
+ expected_output = {
48
+ server_name: 'serverName'.encode('utf-16le'),
49
+ root_share: 'rootShare'.encode('utf-16le'),
50
+ comment: 'comment'.encode('utf-16le'),
51
+ api_flags: 0
52
+ }
53
+ expect(packet.read(new_packet.to_binary_s)).to eq(expected_output)
54
+ end
55
+ end
56
+
57
+
@@ -0,0 +1,34 @@
1
+ RSpec.describe RubySMB::Dcerpc::Dfsnm::NetrDfsAddStdRootResponse do
2
+ subject(:packet) { described_class.new }
3
+
4
+ it { is_expected.to respond_to :error_status }
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 '#error_status' do
14
+ it 'is a NdrUint32 structure' do
15
+ expect(packet.error_status).to be_a RubySMB::Dcerpc::Ndr::NdrUint32
16
+ end
17
+ end
18
+ describe '#initialize_instance' do
19
+ it 'sets #opnum to NETR_DFS_ADD_STD_ROOT constant' do
20
+ expect(packet.opnum).to eq(RubySMB::Dcerpc::Dfsnm::NETR_DFS_ADD_STD_ROOT)
21
+ end
22
+ end
23
+ it 'reads itself' do
24
+ new_packet = described_class.new({
25
+ error_status: 0
26
+ })
27
+ expected_output = {
28
+ error_status: 0
29
+ }
30
+ expect(packet.read(new_packet.to_binary_s)).to eq(expected_output)
31
+ end
32
+ end
33
+
34
+
@@ -0,0 +1,49 @@
1
+ RSpec.describe RubySMB::Dcerpc::Dfsnm::NetrDfsRemoveStdRootRequest do
2
+ subject(:packet) { described_class.new }
3
+
4
+ it { is_expected.to respond_to :server_name }
5
+ it { is_expected.to respond_to :root_share }
6
+ it { is_expected.to respond_to :api_flags }
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 '#server_name' do
16
+ it 'is a NdrConfVarWideStringz structure' do
17
+ expect(packet.server_name).to be_a RubySMB::Dcerpc::Ndr::NdrConfVarWideStringz
18
+ end
19
+ end
20
+ describe '#root_share' do
21
+ it 'is a NdrConfVarWideStringz structure' do
22
+ expect(packet.root_share).to be_a RubySMB::Dcerpc::Ndr::NdrConfVarWideStringz
23
+ end
24
+ end
25
+ describe '#api_flags' do
26
+ it 'is a NdrUint32 structure' do
27
+ expect(packet.api_flags).to be_a RubySMB::Dcerpc::Ndr::NdrUint32
28
+ end
29
+ end
30
+ describe '#initialize_instance' do
31
+ it 'sets #opnum to NETR_DFS_REMOVE_STD_ROOT constant' do
32
+ expect(packet.opnum).to eq(RubySMB::Dcerpc::Dfsnm::NETR_DFS_REMOVE_STD_ROOT)
33
+ end
34
+ end
35
+ it 'reads itself' do
36
+ new_packet = described_class.new({
37
+ server_name: 'serverName',
38
+ root_share: 'rootShare',
39
+ })
40
+ expected_output = {
41
+ server_name: 'serverName'.encode('utf-16le'),
42
+ root_share: 'rootShare'.encode('utf-16le'),
43
+ api_flags: 0
44
+ }
45
+ expect(packet.read(new_packet.to_binary_s)).to eq(expected_output)
46
+ end
47
+ end
48
+
49
+
@@ -0,0 +1,34 @@
1
+ RSpec.describe RubySMB::Dcerpc::Dfsnm::NetrDfsRemoveStdRootResponse do
2
+ subject(:packet) { described_class.new }
3
+
4
+ it { is_expected.to respond_to :error_status }
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 '#error_status' do
14
+ it 'is a NdrUint32 structure' do
15
+ expect(packet.error_status).to be_a RubySMB::Dcerpc::Ndr::NdrUint32
16
+ end
17
+ end
18
+ describe '#initialize_instance' do
19
+ it 'sets #opnum to NETR_DFS_REMOVE_STD_ROOT constant' do
20
+ expect(packet.opnum).to eq(RubySMB::Dcerpc::Dfsnm::NETR_DFS_REMOVE_STD_ROOT)
21
+ end
22
+ end
23
+ it 'reads itself' do
24
+ new_packet = described_class.new({
25
+ error_status: 0
26
+ })
27
+ expected_output = {
28
+ error_status: 0
29
+ }
30
+ expect(packet.read(new_packet.to_binary_s)).to eq(expected_output)
31
+ end
32
+ end
33
+
34
+
@@ -0,0 +1,69 @@
1
+ RSpec.describe RubySMB::Dcerpc::Samr::SamrCreateUser2InDomainRequest do
2
+ subject(:packet) { described_class.new }
3
+
4
+ it { is_expected.to respond_to :domain_handle }
5
+ it { is_expected.to respond_to :name }
6
+ it { is_expected.to respond_to :account_type }
7
+ it { is_expected.to respond_to :desired_access }
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
+
14
+ it 'is a BinData::Record' do
15
+ expect(packet).to be_a(BinData::Record)
16
+ end
17
+
18
+ describe '#domain_handle' do
19
+ it 'is a SamprHandle structure' do
20
+ expect(packet.domain_handle).to be_a RubySMB::Dcerpc::Samr::SamprHandle
21
+ end
22
+ end
23
+
24
+ describe '#name' do
25
+ it 'is a RpcUnicodeString' do
26
+ expect(packet.name).to be_a RubySMB::Dcerpc::RpcUnicodeString
27
+ end
28
+ end
29
+
30
+ describe '#account_type' do
31
+ it 'is a NdrUint32 structure' do
32
+ expect(packet.account_type).to be_a RubySMB::Dcerpc::Ndr::NdrUint32
33
+ end
34
+ end
35
+
36
+ describe '#desired_access' do
37
+ it 'is a NdrUint32 structure' do
38
+ expect(packet.desired_access).to be_a RubySMB::Dcerpc::Ndr::NdrUint32
39
+ end
40
+ end
41
+
42
+ describe '#initialize_instance' do
43
+ it 'sets #opnum to SAMR_CREATE_USER2_IN_DOMAIN constant' do
44
+ expect(packet.opnum).to eq(RubySMB::Dcerpc::Samr::SAMR_CREATE_USER2_IN_DOMAIN)
45
+ end
46
+ end
47
+
48
+ it 'reads itself' do
49
+ new_packet = described_class.new({
50
+ domain_handle: {
51
+ context_handle_attributes: 0,
52
+ context_handle_uuid: "fc873b90-d9a9-46a4-b9ea-f44bb1c272a7"
53
+ },
54
+ name: 'test',
55
+ account_type: 1,
56
+ desired_access: 2
57
+ })
58
+ expected_output = {
59
+ domain_handle: {
60
+ context_handle_attributes: 0,
61
+ context_handle_uuid: "fc873b90-d9a9-46a4-b9ea-f44bb1c272a7"
62
+ },
63
+ name: {:buffer=>"test".encode('utf-16le'), :buffer_length=>8, :maximum_length=>8},
64
+ account_type: 1,
65
+ desired_access: 2
66
+ }
67
+ expect(packet.read(new_packet.to_binary_s)).to eq(expected_output)
68
+ end
69
+ end
@@ -0,0 +1,69 @@
1
+ RSpec.describe RubySMB::Dcerpc::Samr::SamrCreateUser2InDomainResponse do
2
+ subject(:packet) { described_class.new }
3
+
4
+ it { is_expected.to respond_to :user_handle }
5
+ it { is_expected.to respond_to :granted_access }
6
+ it { is_expected.to respond_to :relative_id }
7
+ it { is_expected.to respond_to :error_status }
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
+
14
+ it 'is a BinData::Record' do
15
+ expect(packet).to be_a(BinData::Record)
16
+ end
17
+
18
+ describe '#user_handle' do
19
+ it 'is a SamprHandle structure' do
20
+ expect(packet.user_handle).to be_a RubySMB::Dcerpc::Samr::SamprHandle
21
+ end
22
+ end
23
+
24
+ describe '#granted_access' do
25
+ it 'is a NdrUint32' do
26
+ expect(packet.granted_access).to be_a RubySMB::Dcerpc::Ndr::NdrUint32
27
+ end
28
+ end
29
+
30
+ describe '#relative_id' do
31
+ it 'is a NdrUint32 structure' do
32
+ expect(packet.relative_id).to be_a RubySMB::Dcerpc::Ndr::NdrUint32
33
+ end
34
+ end
35
+
36
+ describe '#error_status' do
37
+ it 'is a NdrUint32 structure' do
38
+ expect(packet.error_status).to be_a RubySMB::Dcerpc::Ndr::NdrUint32
39
+ end
40
+ end
41
+
42
+ describe '#initialize_instance' do
43
+ it 'sets #opnum to SAMR_CREATE_USER2_IN_DOMAIN constant' do
44
+ expect(packet.opnum).to eq(RubySMB::Dcerpc::Samr::SAMR_CREATE_USER2_IN_DOMAIN)
45
+ end
46
+ end
47
+
48
+ it 'reads itself' do
49
+ new_packet = described_class.new({
50
+ user_handle: {
51
+ context_handle_attributes: 0,
52
+ context_handle_uuid: "fc873b90-d9a9-46a4-b9ea-f44bb1c272a7"
53
+ },
54
+ granted_access: 1,
55
+ relative_id: 2,
56
+ error_status: 0x11223344
57
+ })
58
+ expected_output = {
59
+ user_handle: {
60
+ context_handle_attributes: 0,
61
+ context_handle_uuid: "fc873b90-d9a9-46a4-b9ea-f44bb1c272a7"
62
+ },
63
+ granted_access: 1,
64
+ relative_id: 2,
65
+ error_status: 0x11223344
66
+ }
67
+ expect(packet.read(new_packet.to_binary_s)).to eq(expected_output)
68
+ end
69
+ end
@@ -0,0 +1,42 @@
1
+ RSpec.describe RubySMB::Dcerpc::Samr::SamrDeleteUserRequest do
2
+ subject(:packet) { described_class.new }
3
+
4
+ it { is_expected.to respond_to :user_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
+
11
+ it 'is a BinData::Record' do
12
+ expect(packet).to be_a(BinData::Record)
13
+ end
14
+
15
+ describe '#user_handle' do
16
+ it 'is a SamprHandle structure' do
17
+ expect(packet.user_handle).to be_a RubySMB::Dcerpc::Samr::SamprHandle
18
+ end
19
+ end
20
+
21
+ describe '#initialize_instance' do
22
+ it 'sets #opnum to SAMR_DELETE_USER constant' do
23
+ expect(packet.opnum).to eq(RubySMB::Dcerpc::Samr::SAMR_DELETE_USER)
24
+ end
25
+ end
26
+
27
+ it 'reads itself' do
28
+ new_packet = described_class.new({
29
+ user_handle: {
30
+ context_handle_attributes: 0,
31
+ context_handle_uuid: "fc873b90-d9a9-46a4-b9ea-f44bb1c272a7"
32
+ }
33
+ })
34
+ expected_output = {
35
+ user_handle: {
36
+ context_handle_attributes: 0,
37
+ context_handle_uuid: "fc873b90-d9a9-46a4-b9ea-f44bb1c272a7"
38
+ }
39
+ }
40
+ expect(packet.read(new_packet.to_binary_s)).to eq(expected_output)
41
+ end
42
+ end
@@ -0,0 +1,51 @@
1
+ RSpec.describe RubySMB::Dcerpc::Samr::SamrDeleteUserResponse do
2
+ subject(:packet) { described_class.new }
3
+
4
+ it { is_expected.to respond_to :user_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
+
12
+ it 'is a BinData::Record' do
13
+ expect(packet).to be_a(BinData::Record)
14
+ end
15
+
16
+ describe '#user_handle' do
17
+ it 'is a SamprHandle structure' do
18
+ expect(packet.user_handle).to be_a RubySMB::Dcerpc::Samr::SamprHandle
19
+ end
20
+ end
21
+
22
+ describe '#error_status' do
23
+ it 'is a NdrUint32 structure' do
24
+ expect(packet.error_status).to be_a RubySMB::Dcerpc::Ndr::NdrUint32
25
+ end
26
+ end
27
+
28
+ describe '#initialize_instance' do
29
+ it 'sets #opnum to SAMR_DELETE_USER constant' do
30
+ expect(packet.opnum).to eq(RubySMB::Dcerpc::Samr::SAMR_DELETE_USER)
31
+ end
32
+ end
33
+
34
+ it 'reads itself' do
35
+ new_packet = described_class.new({
36
+ user_handle: {
37
+ context_handle_attributes: 0,
38
+ context_handle_uuid: "fc873b90-d9a9-46a4-b9ea-f44bb1c272a7"
39
+ },
40
+ error_status: 0x11223344
41
+ })
42
+ expected_output = {
43
+ user_handle: {
44
+ context_handle_attributes: 0,
45
+ context_handle_uuid: "fc873b90-d9a9-46a4-b9ea-f44bb1c272a7"
46
+ },
47
+ error_status: 0x11223344
48
+ }
49
+ expect(packet.read(new_packet.to_binary_s)).to eq(expected_output)
50
+ end
51
+ end
@@ -0,0 +1,60 @@
1
+ RSpec.describe RubySMB::Dcerpc::Samr::SamrEnumerateDomainsInSamServerRequest do
2
+ subject(:packet) { described_class.new }
3
+
4
+ it { is_expected.to respond_to :server_handle }
5
+ it { is_expected.to respond_to :enumeration_context }
6
+ it { is_expected.to respond_to :prefered_maximum_length }
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
+
13
+ it 'is a BinData::Record' do
14
+ expect(packet).to be_a(BinData::Record)
15
+ end
16
+
17
+ describe '#server_handle' do
18
+ it 'is a SamprHandle structure' do
19
+ expect(packet.server_handle).to be_a RubySMB::Dcerpc::Samr::SamprHandle
20
+ end
21
+ end
22
+
23
+ describe '#enumeration_context' do
24
+ it 'is a NdrUint32 structure' do
25
+ expect(packet.enumeration_context).to be_a RubySMB::Dcerpc::Ndr::NdrUint32
26
+ end
27
+ end
28
+
29
+ describe '#prefered_maximum_length' do
30
+ it 'is a NdrUint32 structure' do
31
+ expect(packet.prefered_maximum_length).to be_a RubySMB::Dcerpc::Ndr::NdrUint32
32
+ end
33
+ end
34
+
35
+ describe '#initialize_instance' do
36
+ it 'sets #opnum to SAMR_ENUMERATE_DOMAINS_IN_SAM_SERVER constant' do
37
+ expect(packet.opnum).to eq(RubySMB::Dcerpc::Samr::SAMR_ENUMERATE_DOMAINS_IN_SAM_SERVER)
38
+ end
39
+ end
40
+
41
+ it 'reads itself' do
42
+ new_packet = described_class.new({
43
+ server_handle: {
44
+ context_handle_attributes: 0,
45
+ context_handle_uuid: "fc873b90-d9a9-46a4-b9ea-f44bb1c272a7"
46
+ },
47
+ enumeration_context: 1,
48
+ prefered_maximum_length: 2
49
+ })
50
+ expected_output = {
51
+ server_handle: {
52
+ context_handle_attributes: 0,
53
+ context_handle_uuid: "fc873b90-d9a9-46a4-b9ea-f44bb1c272a7"
54
+ },
55
+ enumeration_context: 1,
56
+ prefered_maximum_length: 2
57
+ }
58
+ expect(packet.read(new_packet.to_binary_s)).to eq(expected_output)
59
+ end
60
+ end
@@ -0,0 +1,75 @@
1
+ RSpec.describe RubySMB::Dcerpc::Samr::SamrEnumerateDomainsInSamServerResponse do
2
+ subject(:packet) { described_class.new }
3
+
4
+ it { is_expected.to respond_to :enumeration_context }
5
+ it { is_expected.to respond_to :buffer }
6
+ it { is_expected.to respond_to :count_returned }
7
+ it { is_expected.to respond_to :error_status }
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
+
14
+ it 'is a BinData::Record' do
15
+ expect(packet).to be_a(BinData::Record)
16
+ end
17
+
18
+ describe '#enumeration_context' do
19
+ it 'is a NdrUint32 structure' do
20
+ expect(packet.enumeration_context).to be_a RubySMB::Dcerpc::Ndr::NdrUint32
21
+ end
22
+ end
23
+
24
+ describe '#buffer' do
25
+ it 'is a PsamprEnumerationBuffer structure' do
26
+ expect(packet.buffer).to be_a RubySMB::Dcerpc::Samr::PsamprEnumerationBuffer
27
+ end
28
+ end
29
+
30
+ describe '#count_returned' do
31
+ it 'is a NdrUint32 structure' do
32
+ expect(packet.count_returned).to be_a RubySMB::Dcerpc::Ndr::NdrUint32
33
+ end
34
+ end
35
+
36
+ describe '#error_status' do
37
+ it 'is a NdrUint32 structure' do
38
+ expect(packet.error_status).to be_a RubySMB::Dcerpc::Ndr::NdrUint32
39
+ end
40
+ end
41
+
42
+ describe '#initialize_instance' do
43
+ it 'sets #opnum to SAMR_ENUMERATE_DOMAINS_IN_SAM_SERVER constant' do
44
+ expect(packet.opnum).to eq(RubySMB::Dcerpc::Samr::SAMR_ENUMERATE_DOMAINS_IN_SAM_SERVER)
45
+ end
46
+ end
47
+
48
+ it 'reads itself' do
49
+ new_packet = described_class.new({
50
+ enumeration_context: 1,
51
+ buffer: {
52
+ entries_read: 2,
53
+ buffer: [
54
+ {relative_id: 500, name: { buffer_length: 26, maximum_length: 26, buffer: "Builtin".encode('utf-16le') }},
55
+ {relative_id: 501, name: { buffer_length: 10, maximum_length: 10, buffer: "RUBYSMB".encode('utf-16le') }},
56
+ ]
57
+ },
58
+ count_returned: 2,
59
+ error_status: 0x11223344
60
+ })
61
+ expected_output = {
62
+ enumeration_context: 1,
63
+ buffer: {
64
+ entries_read: 2,
65
+ buffer: [
66
+ {relative_id: 500, name: { buffer_length: 26, maximum_length: 26, buffer: "Builtin".encode('utf-16le') }},
67
+ {relative_id: 501, name: { buffer_length: 10, maximum_length: 10, buffer: "RUBYSMB".encode('utf-16le') }},
68
+ ]
69
+ },
70
+ count_returned: 2,
71
+ error_status: 0x11223344
72
+ }
73
+ expect(packet.read(new_packet.to_binary_s)).to eq(expected_output)
74
+ end
75
+ end