ruby_smb 3.0.4 → 3.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (113) hide show
  1. checksums.yaml +4 -4
  2. checksums.yaml.gz.sig +0 -0
  3. data/.github/workflows/verify.yml +1 -1
  4. data/.simplecov +1 -1
  5. data/CONTRIBUTING.md +28 -3
  6. data/README.md +8 -0
  7. data/examples/pwsh_service.rb +112 -0
  8. data/lib/ruby_smb/client/encryption.rb +16 -4
  9. data/lib/ruby_smb/client/negotiation.rb +4 -2
  10. data/lib/ruby_smb/client.rb +18 -2
  11. data/lib/ruby_smb/dcerpc/request.rb +2 -0
  12. data/lib/ruby_smb/dcerpc/svcctl/create_service_w_request.rb +35 -0
  13. data/lib/ruby_smb/dcerpc/svcctl/create_service_w_response.rb +24 -0
  14. data/lib/ruby_smb/dcerpc/svcctl/delete_service_request.rb +21 -0
  15. data/lib/ruby_smb/dcerpc/svcctl/delete_service_response.rb +21 -0
  16. data/lib/ruby_smb/dcerpc/svcctl.rb +66 -5
  17. data/lib/ruby_smb/dcerpc/winreg/open_root_key_request.rb +1 -1
  18. data/lib/ruby_smb/dcerpc/winreg/regsam.rb +1 -1
  19. data/lib/ruby_smb/dcerpc/winreg.rb +1 -1
  20. data/lib/ruby_smb/fscc/file_information.rb +4 -0
  21. data/lib/ruby_smb/server/server_client/encryption.rb +66 -0
  22. data/lib/ruby_smb/server/server_client/negotiation.rb +14 -3
  23. data/lib/ruby_smb/server/server_client/session_setup.rb +18 -3
  24. data/lib/ruby_smb/server/server_client/share_io.rb +17 -0
  25. data/lib/ruby_smb/server/server_client/tree_connect.rb +40 -3
  26. data/lib/ruby_smb/server/server_client.rb +147 -37
  27. data/lib/ruby_smb/server/session.rb +6 -0
  28. data/lib/ruby_smb/server/share/provider/disk/file_system.rb +28 -0
  29. data/lib/ruby_smb/server/share/provider/disk/processor/close.rb +42 -0
  30. data/lib/ruby_smb/server/share/provider/disk/processor/create.rb +143 -0
  31. data/lib/ruby_smb/server/share/provider/disk/processor/query.rb +359 -0
  32. data/lib/ruby_smb/server/share/provider/disk/processor/read.rb +69 -0
  33. data/lib/ruby_smb/server/share/provider/disk/processor.rb +159 -0
  34. data/lib/ruby_smb/server/share/provider/disk.rb +4 -416
  35. data/lib/ruby_smb/server/share/provider/pipe.rb +2 -2
  36. data/lib/ruby_smb/server/share/provider/processor.rb +16 -0
  37. data/lib/ruby_smb/signing.rb +18 -4
  38. data/lib/ruby_smb/smb1/bit_field/directory_access_mask.rb +1 -1
  39. data/lib/ruby_smb/smb1/bit_field/file_access_mask.rb +1 -1
  40. data/lib/ruby_smb/smb1/commands.rb +1 -0
  41. data/lib/ruby_smb/smb1/packet/nt_create_andx_request.rb +11 -1
  42. data/lib/ruby_smb/smb1/packet/nt_trans/create_request.rb +1 -1
  43. data/lib/ruby_smb/smb1/packet/read_andx_response.rb +5 -4
  44. data/lib/ruby_smb/smb1/packet/session_setup_request.rb +12 -4
  45. data/lib/ruby_smb/smb1/packet/trans2/data_block.rb +9 -1
  46. data/lib/ruby_smb/smb1/packet/trans2/find_first2_request.rb +52 -51
  47. data/lib/ruby_smb/smb1/packet/trans2/find_first2_response.rb +37 -37
  48. data/lib/ruby_smb/smb1/packet/trans2/find_information_level/find_file_both_directory_info.rb +48 -0
  49. data/lib/ruby_smb/smb1/packet/trans2/find_information_level.rb +28 -15
  50. data/lib/ruby_smb/smb1/packet/trans2/find_next2_request.rb +51 -51
  51. data/lib/ruby_smb/smb1/packet/trans2/find_next2_response.rb +36 -36
  52. data/lib/ruby_smb/smb1/packet/trans2/open2_request.rb +40 -39
  53. data/lib/ruby_smb/smb1/packet/trans2/open2_response.rb +40 -40
  54. data/lib/ruby_smb/smb1/packet/trans2/query_file_information_request.rb +60 -0
  55. data/lib/ruby_smb/smb1/packet/trans2/query_file_information_response.rb +59 -0
  56. data/lib/ruby_smb/smb1/packet/trans2/query_fs_information_level/query_fs_attribute_info.rb +31 -0
  57. data/lib/ruby_smb/smb1/packet/trans2/query_fs_information_level.rb +40 -0
  58. data/lib/ruby_smb/smb1/packet/trans2/query_fs_information_request.rb +46 -0
  59. data/lib/ruby_smb/smb1/packet/trans2/query_fs_information_response.rb +59 -0
  60. data/lib/ruby_smb/smb1/packet/trans2/query_information_level/query_file_basic_info.rb +23 -0
  61. data/lib/ruby_smb/smb1/packet/trans2/query_information_level/query_file_standard_info.rb +22 -0
  62. data/lib/ruby_smb/smb1/packet/trans2/query_information_level.rb +62 -0
  63. data/lib/ruby_smb/smb1/packet/trans2/query_path_information_request.rb +65 -0
  64. data/lib/ruby_smb/smb1/packet/trans2/query_path_information_response.rb +59 -0
  65. data/lib/ruby_smb/smb1/packet/trans2/request.rb +24 -8
  66. data/lib/ruby_smb/smb1/packet/trans2/request_secondary.rb +4 -4
  67. data/lib/ruby_smb/smb1/packet/trans2/response.rb +29 -20
  68. data/lib/ruby_smb/smb1/packet/trans2/set_file_information_request.rb +42 -42
  69. data/lib/ruby_smb/smb1/packet/trans2/set_file_information_response.rb +23 -23
  70. data/lib/ruby_smb/smb1/packet/trans2/subcommands.rb +23 -5
  71. data/lib/ruby_smb/smb1/packet/trans2.rb +4 -0
  72. data/lib/ruby_smb/smb1/packet/tree_connect_request.rb +4 -1
  73. data/lib/ruby_smb/smb2/bit_field/directory_access_mask.rb +1 -1
  74. data/lib/ruby_smb/smb2/bit_field/file_access_mask.rb +1 -1
  75. data/lib/ruby_smb/smb2/negotiate_context.rb +10 -1
  76. data/lib/ruby_smb/smb2/packet/session_setup_request.rb +11 -0
  77. data/lib/ruby_smb/smb2/packet/transform_header.rb +7 -7
  78. data/lib/ruby_smb/smb2.rb +1 -0
  79. data/lib/ruby_smb/version.rb +1 -1
  80. data/ruby_smb.gemspec +1 -1
  81. data/spec/lib/ruby_smb/client_spec.rb +20 -6
  82. data/spec/lib/ruby_smb/dcerpc/svcctl/create_service_w_request_spec.rb +143 -0
  83. data/spec/lib/ruby_smb/dcerpc/svcctl/create_service_w_response_spec.rb +45 -0
  84. data/spec/lib/ruby_smb/dcerpc/svcctl/delete_service_request_spec.rb +29 -0
  85. data/spec/lib/ruby_smb/dcerpc/svcctl/delete_service_response_spec.rb +29 -0
  86. data/spec/lib/ruby_smb/dcerpc/winreg/open_root_key_request_spec.rb +8 -8
  87. data/spec/lib/ruby_smb/dcerpc/winreg/regsam_spec.rb +1 -1
  88. data/spec/lib/ruby_smb/dcerpc/winreg_spec.rb +1 -1
  89. data/spec/lib/ruby_smb/smb1/bit_field/directory_access_mask_spec.rb +4 -4
  90. data/spec/lib/ruby_smb/smb1/bit_field/file_access_mask_spec.rb +4 -4
  91. data/spec/lib/ruby_smb/smb1/packet/trans2/find_first2_request_spec.rb +2 -2
  92. data/spec/lib/ruby_smb/smb1/packet/trans2/find_first2_response_spec.rb +36 -2
  93. data/spec/lib/ruby_smb/smb1/packet/trans2/find_next2_request_spec.rb +2 -2
  94. data/spec/lib/ruby_smb/smb1/packet/trans2/find_next2_response_spec.rb +35 -1
  95. data/spec/lib/ruby_smb/smb1/packet/trans2/query_file_information_request_spec.rb +74 -0
  96. data/spec/lib/ruby_smb/smb1/packet/trans2/query_file_information_response_spec.rb +96 -0
  97. data/spec/lib/ruby_smb/smb1/packet/trans2/query_fs_information_request_spec.rb +62 -0
  98. data/spec/lib/ruby_smb/smb1/packet/trans2/query_fs_information_response_spec.rb +88 -0
  99. data/spec/lib/ruby_smb/smb1/packet/trans2/query_path_information_request_spec.rb +79 -0
  100. data/spec/lib/ruby_smb/smb1/packet/trans2/query_path_information_response_spec.rb +96 -0
  101. data/spec/lib/ruby_smb/smb1/packet/trans2/request_spec.rb +2 -2
  102. data/spec/lib/ruby_smb/smb1/packet/trans2/response_spec.rb +3 -3
  103. data/spec/lib/ruby_smb/smb1/packet/trans2/set_file_information_request_spec.rb +3 -2
  104. data/spec/lib/ruby_smb/smb1/packet/trans2/set_file_information_response_spec.rb +7 -2
  105. data/spec/lib/ruby_smb/smb1/tree_spec.rb +8 -3
  106. data/spec/lib/ruby_smb/smb2/bit_field/directory_access_mask_spec.rb +4 -4
  107. data/spec/lib/ruby_smb/smb2/bit_field/file_access_mask_spec.rb +4 -4
  108. data/spec/lib/ruby_smb/smb2/packet/transform_header_spec.rb +2 -2
  109. data/spec/lib/ruby_smb/smb2/tree_spec.rb +6 -1
  110. data/spec/spec_helper.rb +2 -3
  111. data.tar.gz.sig +0 -0
  112. metadata +48 -4
  113. metadata.gz.sig +0 -0
@@ -24,7 +24,7 @@ RSpec.describe RubySMB::SMB1::Packet::Trans2::FindNext2Response do
24
24
  describe '#parameter_block' do
25
25
  subject(:parameter_block) { packet.parameter_block }
26
26
 
27
- it 'should have the setup set to the OPEN2 subcommand' do
27
+ it 'should have the setup set to the FIND_NEXT2 subcommand' do
28
28
  expect(parameter_block.setup).to include RubySMB::SMB1::Packet::Trans2::Subcommands::FIND_NEXT2
29
29
  end
30
30
  end
@@ -56,6 +56,40 @@ RSpec.describe RubySMB::SMB1::Packet::Trans2::FindNext2Response do
56
56
  subject(:data) { data_block.trans2_data }
57
57
 
58
58
  it { is_expected.to respond_to :buffer }
59
+
60
+ describe '#buffer' do
61
+ it 'is a String field' do
62
+ expect(data.buffer).to be_a BinData::String
63
+ end
64
+ end
65
+
66
+ context 'when the buffer is empty' do
67
+ before :each do
68
+ data.buffer = ''
69
+ end
70
+
71
+ it 'should not be padded' do
72
+ expect(data_block.pad2.num_bytes).to eq 0
73
+ end
74
+
75
+ it 'should read its own binary representation' do
76
+ expect(packet.class.read(packet.to_binary_s).data_block.trans2_data.buffer).to eq ''
77
+ end
78
+ end
79
+
80
+ context 'when the buffer is not empty' do
81
+ before :each do
82
+ data.buffer = 'test'
83
+ end
84
+
85
+ it 'should be padded to a 4-byte boundary' do
86
+ expect(data_block.trans2_data.abs_offset % 4).to eq 0
87
+ end
88
+
89
+ it 'should read its own binary representation' do
90
+ expect(packet.class.read(packet.to_binary_s).data_block.trans2_data.buffer).to eq 'test'
91
+ end
92
+ end
59
93
  end
60
94
  end
61
95
 
@@ -0,0 +1,74 @@
1
+ include RubySMB::Fscc::FileInformation
2
+
3
+ RSpec.describe RubySMB::SMB1::Packet::Trans2::QueryFileInformationRequest do
4
+ subject(:packet) { described_class.new }
5
+
6
+ describe '#smb_header' do
7
+ subject(:header) { packet.smb_header }
8
+
9
+ it 'is a standard SMB Header' do
10
+ expect(header).to be_a RubySMB::SMB1::SMBHeader
11
+ end
12
+
13
+ it 'should have the command set to SMB_COM_TRANSACTION2' do
14
+ expect(header.command).to eq RubySMB::SMB1::Commands::SMB_COM_TRANSACTION2
15
+ end
16
+
17
+ it 'should not have the response flag set' do
18
+ expect(header.flags.reply).to eq 0
19
+ end
20
+ end
21
+
22
+ describe '#parameter_block' do
23
+ subject(:parameter_block) { packet.parameter_block }
24
+
25
+ it 'is a standard ParameterBlock' do
26
+ expect(parameter_block).to be_a RubySMB::SMB1::Packet::Trans2::Request::ParameterBlock
27
+ end
28
+
29
+ it 'should have the setup set to the QUERY_FILE_INFORMATION subcommand' do
30
+ expect(parameter_block.setup).to include RubySMB::SMB1::Packet::Trans2::Subcommands::QUERY_FILE_INFORMATION
31
+ end
32
+ end
33
+
34
+ describe '#data_block' do
35
+ subject(:data_block) { packet.data_block }
36
+
37
+ it 'is a standard DataBlock' do
38
+ expect(data_block).to be_a RubySMB::SMB1::DataBlock
39
+ end
40
+
41
+ it { is_expected.to respond_to :name }
42
+ it { is_expected.to respond_to :trans2_parameters }
43
+ it { is_expected.to respond_to :trans2_data }
44
+
45
+ it 'should keep #trans2_parameters 4-byte aligned' do
46
+ expect(data_block.trans2_parameters.abs_offset % 4).to eq 0
47
+ end
48
+
49
+ it 'should keep #trans2_data 4-byte aligned' do
50
+ data_block.trans2_parameters.information_level = FILE_DISPOSITION_INFORMATION + SMB_INFO_PASSTHROUGH
51
+ expect(data_block.trans2_data.abs_offset % 4).to eq 0 if data_block.trans2_data.num_bytes != 0
52
+ end
53
+
54
+ describe '#trans2_parameters' do
55
+ subject(:parameters) { data_block.trans2_parameters }
56
+
57
+ it { is_expected.to respond_to :fid }
58
+ it { is_expected.to respond_to :information_level }
59
+
60
+ describe '#fid' do
61
+ it 'is a 16-bit field' do
62
+ expect(parameters.fid).to be_a BinData::Uint16le
63
+ end
64
+ end
65
+
66
+ describe '#information_level' do
67
+ it 'is a 16-bit field' do
68
+ expect(parameters.information_level).to be_a BinData::Uint16le
69
+ end
70
+ end
71
+ end
72
+ end
73
+ end
74
+
@@ -0,0 +1,96 @@
1
+ RSpec.describe RubySMB::SMB1::Packet::Trans2::QueryFileInformationResponse do
2
+ subject(:packet) { described_class.new }
3
+
4
+ describe '#smb_header' do
5
+ subject(:header) { packet.smb_header }
6
+
7
+ it 'is a standard SMB Header' do
8
+ expect(header).to be_a RubySMB::SMB1::SMBHeader
9
+ end
10
+
11
+ it 'should have the command set to SMB_COM_TRANSACTION2' do
12
+ expect(header.command).to eq RubySMB::SMB1::Commands::SMB_COM_TRANSACTION2
13
+ end
14
+
15
+ it 'should have the response flag set' do
16
+ expect(header.flags.reply).to eq 1
17
+ end
18
+ end
19
+
20
+ describe '#parameter_block' do
21
+ subject(:parameter_block) { packet.parameter_block }
22
+
23
+ it 'should have the setup set to the QUERY_FILE_INFORMATION subcommand' do
24
+ expect(parameter_block.setup).to include RubySMB::SMB1::Packet::Trans2::Subcommands::QUERY_FILE_INFORMATION
25
+ end
26
+ end
27
+
28
+ describe '#data_block' do
29
+ subject(:data_block) { packet.data_block }
30
+
31
+ it 'is a standard DataBlock' do
32
+ expect(data_block).to be_a RubySMB::SMB1::DataBlock
33
+ end
34
+
35
+ it { is_expected.to respond_to :name }
36
+ it { is_expected.to respond_to :trans2_parameters }
37
+ it { is_expected.to respond_to :trans2_data }
38
+
39
+ it 'should keep #trans2_parameters 4-byte aligned' do
40
+ expect(data_block.trans2_parameters.abs_offset % 4).to eq 0
41
+ end
42
+
43
+ describe '#trans2_parameters' do
44
+ subject(:parameters) { data_block.trans2_parameters }
45
+
46
+ it { is_expected.to respond_to :ea_error_offset }
47
+
48
+ describe '#ea_error_offset' do
49
+ it 'is a 16-bit field' do
50
+ expect(parameters.ea_error_offset).to be_a BinData::Uint16le
51
+ end
52
+ end
53
+ end
54
+
55
+ describe '#trans2_data' do
56
+ subject(:data) { data_block.trans2_data }
57
+
58
+ it { is_expected.to respond_to :buffer }
59
+
60
+ describe '#buffer' do
61
+ it 'is a String field' do
62
+ expect(data.buffer).to be_a BinData::String
63
+ end
64
+ end
65
+
66
+ context 'when the buffer is empty' do
67
+ before :each do
68
+ data.buffer = ''
69
+ end
70
+
71
+ it 'should not be padded' do
72
+ expect(data_block.pad2.num_bytes).to eq 0
73
+ end
74
+
75
+ it 'should read its own binary representation' do
76
+ expect(packet.class.read(packet.to_binary_s).data_block.trans2_data.buffer).to eq ''
77
+ end
78
+ end
79
+
80
+ context 'when the buffer is not empty' do
81
+ before :each do
82
+ data.buffer = 'test'
83
+ end
84
+
85
+ it 'should be padded to a 4-byte boundary' do
86
+ expect(data_block.trans2_data.abs_offset % 4).to eq 0
87
+ end
88
+
89
+ it 'should read its own binary representation' do
90
+ expect(packet.class.read(packet.to_binary_s).data_block.trans2_data.buffer).to eq 'test'
91
+ end
92
+ end
93
+ end
94
+ end
95
+
96
+ end
@@ -0,0 +1,62 @@
1
+ include RubySMB::Fscc::FileInformation
2
+
3
+ RSpec.describe RubySMB::SMB1::Packet::Trans2::QueryFsInformationRequest do
4
+ subject(:packet) { described_class.new }
5
+
6
+ describe '#smb_header' do
7
+ subject(:header) { packet.smb_header }
8
+
9
+ it 'is a standard SMB Header' do
10
+ expect(header).to be_a RubySMB::SMB1::SMBHeader
11
+ end
12
+
13
+ it 'should have the command set to SMB_COM_TRANSACTION2' do
14
+ expect(header.command).to eq RubySMB::SMB1::Commands::SMB_COM_TRANSACTION2
15
+ end
16
+
17
+ it 'should not have the response flag set' do
18
+ expect(header.flags.reply).to eq 0
19
+ end
20
+ end
21
+
22
+ describe '#parameter_block' do
23
+ subject(:parameter_block) { packet.parameter_block }
24
+
25
+ it 'is a standard ParameterBlock' do
26
+ expect(parameter_block).to be_a RubySMB::SMB1::Packet::Trans2::Request::ParameterBlock
27
+ end
28
+
29
+ it 'should have the setup set to the QUERY_FS_INFORMATION subcommand' do
30
+ expect(parameter_block.setup).to include RubySMB::SMB1::Packet::Trans2::Subcommands::QUERY_FS_INFORMATION
31
+ end
32
+ end
33
+
34
+ describe '#data_block' do
35
+ subject(:data_block) { packet.data_block }
36
+
37
+ it 'is a standard DataBlock' do
38
+ expect(data_block).to be_a RubySMB::SMB1::DataBlock
39
+ end
40
+
41
+ it { is_expected.to respond_to :name }
42
+ it { is_expected.to respond_to :trans2_parameters }
43
+ it { is_expected.to_not respond_to :trans2_data }
44
+
45
+ it 'should keep #trans2_parameters 4-byte aligned' do
46
+ expect(data_block.trans2_parameters.abs_offset % 4).to eq 0
47
+ end
48
+
49
+ describe '#trans2_parameters' do
50
+ subject(:parameters) { data_block.trans2_parameters }
51
+
52
+ it { is_expected.to respond_to :information_level }
53
+
54
+ describe '#information_level' do
55
+ it 'is a 16-bit field' do
56
+ expect(parameters.information_level).to be_a BinData::Uint16le
57
+ end
58
+ end
59
+ end
60
+ end
61
+ end
62
+
@@ -0,0 +1,88 @@
1
+ RSpec.describe RubySMB::SMB1::Packet::Trans2::QueryFsInformationResponse do
2
+ subject(:packet) { described_class.new }
3
+
4
+ describe '#smb_header' do
5
+ subject(:header) { packet.smb_header }
6
+
7
+ it 'is a standard SMB Header' do
8
+ expect(header).to be_a RubySMB::SMB1::SMBHeader
9
+ end
10
+
11
+ it 'should have the command set to SMB_COM_TRANSACTION2' do
12
+ expect(header.command).to eq RubySMB::SMB1::Commands::SMB_COM_TRANSACTION2
13
+ end
14
+
15
+ it 'should have the response flag set' do
16
+ expect(header.flags.reply).to eq 1
17
+ end
18
+ end
19
+
20
+ describe '#parameter_block' do
21
+ subject(:parameter_block) { packet.parameter_block }
22
+
23
+ it 'should have the setup set to the QUERY_FS_INFORMATION subcommand' do
24
+ expect(parameter_block.setup).to include RubySMB::SMB1::Packet::Trans2::Subcommands::QUERY_FS_INFORMATION
25
+ end
26
+ end
27
+
28
+ describe '#data_block' do
29
+ subject(:data_block) { packet.data_block }
30
+
31
+ it 'is a standard DataBlock' do
32
+ expect(data_block).to be_a RubySMB::SMB1::DataBlock
33
+ end
34
+
35
+ it { is_expected.to respond_to :name }
36
+ it { is_expected.to respond_to :trans2_parameters }
37
+ it { is_expected.to respond_to :trans2_data }
38
+
39
+ it 'should keep #trans2_parameters 4-byte aligned' do
40
+ expect(data_block.trans2_parameters.abs_offset % 4).to eq 0
41
+ end
42
+
43
+ describe '#trans2_parameters' do
44
+ subject(:parameters) { data_block.trans2_parameters }
45
+ end
46
+
47
+ describe '#trans2_data' do
48
+ subject(:data) { data_block.trans2_data }
49
+
50
+ it { is_expected.to respond_to :buffer }
51
+
52
+ describe '#buffer' do
53
+ it 'is a String field' do
54
+ expect(data.buffer).to be_a BinData::String
55
+ end
56
+ end
57
+
58
+ context 'when the buffer is empty' do
59
+ before :each do
60
+ data.buffer = ''
61
+ end
62
+
63
+ it 'should not be padded' do
64
+ expect(data_block.pad2.num_bytes).to eq 0
65
+ end
66
+
67
+ it 'should read its own binary representation' do
68
+ expect(packet.class.read(packet.to_binary_s).data_block.trans2_data.buffer).to eq ''
69
+ end
70
+ end
71
+
72
+ context 'when the buffer is not empty' do
73
+ before :each do
74
+ data.buffer = 'test'
75
+ end
76
+
77
+ it 'should be padded to a 4-byte boundary' do
78
+ expect(data_block.trans2_data.abs_offset % 4).to eq 0
79
+ end
80
+
81
+ it 'should read its own binary representation' do
82
+ expect(packet.class.read(packet.to_binary_s).data_block.trans2_data.buffer).to eq 'test'
83
+ end
84
+ end
85
+ end
86
+ end
87
+
88
+ end
@@ -0,0 +1,79 @@
1
+ include RubySMB::Fscc::FileInformation
2
+
3
+ RSpec.describe RubySMB::SMB1::Packet::Trans2::QueryPathInformationRequest do
4
+ subject(:packet) { described_class.new }
5
+
6
+ describe '#smb_header' do
7
+ subject(:header) { packet.smb_header }
8
+
9
+ it 'is a standard SMB Header' do
10
+ expect(header).to be_a RubySMB::SMB1::SMBHeader
11
+ end
12
+
13
+ it 'should have the command set to SMB_COM_TRANSACTION2' do
14
+ expect(header.command).to eq RubySMB::SMB1::Commands::SMB_COM_TRANSACTION2
15
+ end
16
+
17
+ it 'should not have the response flag set' do
18
+ expect(header.flags.reply).to eq 0
19
+ end
20
+ end
21
+
22
+ describe '#parameter_block' do
23
+ subject(:parameter_block) { packet.parameter_block }
24
+
25
+ it 'is a standard ParameterBlock' do
26
+ expect(parameter_block).to be_a RubySMB::SMB1::Packet::Trans2::Request::ParameterBlock
27
+ end
28
+
29
+ it 'should have the setup set to the QUERY_PATH_INFORMATION subcommand' do
30
+ expect(parameter_block.setup).to include RubySMB::SMB1::Packet::Trans2::Subcommands::QUERY_PATH_INFORMATION
31
+ end
32
+ end
33
+
34
+ describe '#data_block' do
35
+ subject(:data_block) { packet.data_block }
36
+
37
+ it 'is a standard DataBlock' do
38
+ expect(data_block).to be_a RubySMB::SMB1::DataBlock
39
+ end
40
+
41
+ it { is_expected.to respond_to :name }
42
+ it { is_expected.to respond_to :trans2_parameters }
43
+ it { is_expected.to respond_to :trans2_data }
44
+
45
+ it 'should keep #trans2_parameters 4-byte aligned' do
46
+ expect(data_block.trans2_parameters.abs_offset % 4).to eq 0
47
+ end
48
+
49
+ it 'should keep #trans2_data 4-byte aligned' do
50
+ data_block.trans2_parameters.information_level = FILE_DISPOSITION_INFORMATION + SMB_INFO_PASSTHROUGH
51
+ expect(data_block.trans2_data.abs_offset % 4).to eq 0 if data_block.trans2_data.num_bytes != 0
52
+ end
53
+
54
+ describe '#trans2_parameters' do
55
+ subject(:parameters) { data_block.trans2_parameters }
56
+
57
+ it { is_expected.to respond_to :information_level }
58
+ it { is_expected.to respond_to :filename }
59
+
60
+ describe '#information_level' do
61
+ it 'is a 16-bit field' do
62
+ expect(parameters.information_level).to be_a BinData::Uint16le
63
+ end
64
+ end
65
+
66
+ describe '#filename' do
67
+ it 'is a BinData::Choice' do
68
+ expect(parameters.filename).to be_a BinData::Choice
69
+ end
70
+
71
+ it 'responds to #encode' do
72
+ expect(parameters.filename).to respond_to :encode
73
+ expect(parameters.filename.encode).to be_a String
74
+ end
75
+ end
76
+ end
77
+ end
78
+ end
79
+
@@ -0,0 +1,96 @@
1
+ RSpec.describe RubySMB::SMB1::Packet::Trans2::QueryPathInformationResponse do
2
+ subject(:packet) { described_class.new }
3
+
4
+ describe '#smb_header' do
5
+ subject(:header) { packet.smb_header }
6
+
7
+ it 'is a standard SMB Header' do
8
+ expect(header).to be_a RubySMB::SMB1::SMBHeader
9
+ end
10
+
11
+ it 'should have the command set to SMB_COM_TRANSACTION2' do
12
+ expect(header.command).to eq RubySMB::SMB1::Commands::SMB_COM_TRANSACTION2
13
+ end
14
+
15
+ it 'should have the response flag set' do
16
+ expect(header.flags.reply).to eq 1
17
+ end
18
+ end
19
+
20
+ describe '#parameter_block' do
21
+ subject(:parameter_block) { packet.parameter_block }
22
+
23
+ it 'should have the setup set to the QUERY_PATH_INFORMATION subcommand' do
24
+ expect(parameter_block.setup).to include RubySMB::SMB1::Packet::Trans2::Subcommands::QUERY_PATH_INFORMATION
25
+ end
26
+ end
27
+
28
+ describe '#data_block' do
29
+ subject(:data_block) { packet.data_block }
30
+
31
+ it 'is a standard DataBlock' do
32
+ expect(data_block).to be_a RubySMB::SMB1::DataBlock
33
+ end
34
+
35
+ it { is_expected.to respond_to :name }
36
+ it { is_expected.to respond_to :trans2_parameters }
37
+ it { is_expected.to respond_to :trans2_data }
38
+
39
+ it 'should keep #trans2_parameters 4-byte aligned' do
40
+ expect(data_block.trans2_parameters.abs_offset % 4).to eq 0
41
+ end
42
+
43
+ describe '#trans2_parameters' do
44
+ subject(:parameters) { data_block.trans2_parameters }
45
+
46
+ it { is_expected.to respond_to :ea_error_offset }
47
+
48
+ describe '#ea_error_offset' do
49
+ it 'is a 16-bit field' do
50
+ expect(parameters.ea_error_offset).to be_a BinData::Uint16le
51
+ end
52
+ end
53
+ end
54
+
55
+ describe '#trans2_data' do
56
+ subject(:data) { data_block.trans2_data }
57
+
58
+ it { is_expected.to respond_to :buffer }
59
+
60
+ describe '#buffer' do
61
+ it 'is a String field' do
62
+ expect(data.buffer).to be_a BinData::String
63
+ end
64
+ end
65
+
66
+ context 'when the buffer is empty' do
67
+ before :each do
68
+ data.buffer = ''
69
+ end
70
+
71
+ it 'should not be padded' do
72
+ expect(data_block.pad2.num_bytes).to eq 0
73
+ end
74
+
75
+ it 'should read its own binary representation' do
76
+ expect(packet.class.read(packet.to_binary_s).data_block.trans2_data.buffer).to eq ''
77
+ end
78
+ end
79
+
80
+ context 'when the buffer is not empty' do
81
+ before :each do
82
+ data.buffer = 'test'
83
+ end
84
+
85
+ it 'should be padded to a 4-byte boundary' do
86
+ expect(data_block.trans2_data.abs_offset % 4).to eq 0
87
+ end
88
+
89
+ it 'should read its own binary representation' do
90
+ expect(packet.class.read(packet.to_binary_s).data_block.trans2_data.buffer).to eq 'test'
91
+ end
92
+ end
93
+ end
94
+ end
95
+
96
+ end
@@ -75,7 +75,7 @@ RSpec.describe RubySMB::SMB1::Packet::Trans2::Request do
75
75
  subject(:data_block) { packet.data_block }
76
76
 
77
77
  it 'is a standard DataBlock' do
78
- expect(data_block).to be_a RubySMB::SMB1::DataBlock
78
+ expect(data_block).to be_a BinData::Choice
79
79
  end
80
80
 
81
81
  it { is_expected.to respond_to :name }
@@ -88,7 +88,7 @@ RSpec.describe RubySMB::SMB1::Packet::Trans2::Request do
88
88
 
89
89
  it 'should keep #trans2_data 4-byte aligned' do
90
90
  data_block.trans2_parameters = 'a'
91
- expect(data_block.trans2_data.abs_offset % 4).to eq 0
91
+ expect(data_block.trans2_data.abs_offset % 4).to eq 0 if data_block.trans2_data.num_bytes != 0
92
92
  end
93
93
  end
94
94
  end
@@ -44,7 +44,7 @@ RSpec.describe RubySMB::SMB1::Packet::Trans2::Response do
44
44
  end
45
45
 
46
46
  describe 'parameter_offset' do
47
- it ' contains the absolute_offset to the data_block trans2_parameters field' do
47
+ it 'contains the absolute_offset to the data_block trans2_parameters field' do
48
48
  expect(parameter_block.parameter_offset).to eq packet.data_block.trans2_parameters.abs_offset
49
49
  end
50
50
  end
@@ -67,7 +67,7 @@ RSpec.describe RubySMB::SMB1::Packet::Trans2::Response do
67
67
  subject(:data_block) { packet.data_block }
68
68
 
69
69
  it 'is a Trans2 DataBlock' do
70
- expect(data_block).to be_a RubySMB::SMB1::Packet::Trans2::DataBlock
70
+ expect(data_block).to be_a BinData::Choice
71
71
  end
72
72
 
73
73
  it { is_expected.to respond_to :trans2_parameters }
@@ -79,7 +79,7 @@ RSpec.describe RubySMB::SMB1::Packet::Trans2::Response do
79
79
 
80
80
  it 'should keep #trans2_data 4-byte aligned' do
81
81
  data_block.trans2_parameters = 'a'
82
- expect(data_block.trans2_data.abs_offset % 4).to eq 0
82
+ expect(data_block.trans2_data.abs_offset % 4).to eq 0 if data_block.trans2_data.num_bytes != 0
83
83
  end
84
84
  end
85
85
  end
@@ -26,7 +26,7 @@ RSpec.describe RubySMB::SMB1::Packet::Trans2::SetFileInformationRequest do
26
26
  expect(parameter_block).to be_a RubySMB::SMB1::Packet::Trans2::Request::ParameterBlock
27
27
  end
28
28
 
29
- it 'should have the setup set to the OPEN2 subcommand' do
29
+ it 'should have the setup set to the SET_FILE_INFORMATION subcommand' do
30
30
  expect(parameter_block.setup).to include RubySMB::SMB1::Packet::Trans2::Subcommands::SET_FILE_INFORMATION
31
31
  end
32
32
  end
@@ -47,7 +47,8 @@ RSpec.describe RubySMB::SMB1::Packet::Trans2::SetFileInformationRequest do
47
47
  end
48
48
 
49
49
  it 'should keep #trans2_data 4-byte aligned' do
50
- expect(data_block.trans2_data.abs_offset % 4).to eq 0
50
+ data_block.trans2_parameters.information_level = FILE_DISPOSITION_INFORMATION + SMB_INFO_PASSTHROUGH
51
+ expect(data_block.trans2_data.abs_offset % 4).to eq 0 if data_block.trans2_data.num_bytes != 0
51
52
  end
52
53
 
53
54
  describe '#trans2_parameters' do
@@ -8,7 +8,7 @@ RSpec.describe RubySMB::SMB1::Packet::Trans2::SetFileInformationResponse do
8
8
  expect(header).to be_a RubySMB::SMB1::SMBHeader
9
9
  end
10
10
 
11
- it 'should have the command set to SMB_COM_NEGOTIATE' do
11
+ it 'should have the command set to SMB_COM_TRANSACTION2' do
12
12
  expect(header.command).to eq RubySMB::SMB1::Commands::SMB_COM_TRANSACTION2
13
13
  end
14
14
 
@@ -20,7 +20,7 @@ RSpec.describe RubySMB::SMB1::Packet::Trans2::SetFileInformationResponse do
20
20
  describe '#parameter_block' do
21
21
  subject(:parameter_block) { packet.parameter_block }
22
22
 
23
- it 'should have the setup set to the OPEN2 subcommand' do
23
+ it 'should have the setup set to the SET_FILE_INFORMATION subcommand' do
24
24
  expect(parameter_block.setup).to include RubySMB::SMB1::Packet::Trans2::Subcommands::SET_FILE_INFORMATION
25
25
  end
26
26
  end
@@ -28,7 +28,12 @@ RSpec.describe RubySMB::SMB1::Packet::Trans2::SetFileInformationResponse do
28
28
  describe '#data_block' do
29
29
  subject(:data_block) { packet.data_block }
30
30
 
31
+ it 'is a standard DataBlock' do
32
+ expect(data_block).to be_a RubySMB::SMB1::DataBlock
33
+ end
34
+
31
35
  it { is_expected.to respond_to :trans2_parameters }
36
+ it { is_expected.to_not respond_to :trans2_data }
32
37
 
33
38
  it 'should keep #trans2_parameters 4-byte aligned' do
34
39
  expect(data_block.trans2_parameters.abs_offset % 4).to eq 0
@@ -95,7 +95,7 @@ RSpec.describe RubySMB::SMB1::Tree do
95
95
  describe 'filename' do
96
96
  it 'takes the filename as an argument' do
97
97
  allow(client).to receive(:send_recv) do |packet|
98
- expect(packet.data_block.file_name).to eq(filename)
98
+ expect(packet.data_block.file_name.to_binary_s).to eq(filename)
99
99
  nt_create_andx_response.to_binary_s
100
100
  end
101
101
  tree.open_file(filename: filename)
@@ -103,7 +103,7 @@ RSpec.describe RubySMB::SMB1::Tree do
103
103
 
104
104
  it 'adds the null termination to the filename if missing' do
105
105
  allow(client).to receive(:send_recv) do |packet|
106
- expect(packet.data_block.file_name).to eq(filename)
106
+ expect(packet.data_block.file_name.to_binary_s).to eq(filename)
107
107
  nt_create_andx_response.to_binary_s
108
108
  end
109
109
  tree.open_file(filename: filename.chop)
@@ -113,11 +113,16 @@ RSpec.describe RubySMB::SMB1::Tree do
113
113
  unicode_filename = filename.encode('UTF-16LE')
114
114
  nt_create_andx_req.smb_header.flags2.unicode = 1
115
115
  allow(client).to receive(:send_recv) do |packet|
116
- expect(packet.data_block.file_name).to eq(unicode_filename.b)
116
+ expect(packet.data_block.file_name.to_binary_s).to eq(unicode_filename.b)
117
117
  nt_create_andx_response.to_binary_s
118
118
  end
119
119
  tree.open_file(filename: unicode_filename.chop)
120
120
  end
121
+
122
+ it 'removes the leading \\ from the filename if needed' do
123
+ expect(tree).to receive(:_open).with(filename: filename)
124
+ tree.open_file(filename: '\\' + filename)
125
+ end
121
126
  end
122
127
 
123
128
  describe 'flags' do