ruby_smb 1.0.3 → 1.0.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (108) hide show
  1. checksums.yaml +4 -4
  2. checksums.yaml.gz.sig +0 -0
  3. data.tar.gz.sig +0 -0
  4. data/lib/ruby_smb/client.rb +26 -4
  5. data/lib/ruby_smb/client/authentication.rb +43 -25
  6. data/lib/ruby_smb/client/echo.rb +20 -2
  7. data/lib/ruby_smb/client/negotiation.rb +27 -12
  8. data/lib/ruby_smb/client/tree_connect.rb +20 -14
  9. data/lib/ruby_smb/error.rb +40 -1
  10. data/lib/ruby_smb/generic_packet.rb +33 -4
  11. data/lib/ruby_smb/smb1/dcerpc.rb +7 -2
  12. data/lib/ruby_smb/smb1/file.rb +60 -11
  13. data/lib/ruby_smb/smb1/packet/close_request.rb +2 -5
  14. data/lib/ruby_smb/smb1/packet/close_response.rb +2 -1
  15. data/lib/ruby_smb/smb1/packet/echo_request.rb +2 -4
  16. data/lib/ruby_smb/smb1/packet/echo_response.rb +2 -1
  17. data/lib/ruby_smb/smb1/packet/empty_packet.rb +7 -0
  18. data/lib/ruby_smb/smb1/packet/logoff_request.rb +2 -4
  19. data/lib/ruby_smb/smb1/packet/logoff_response.rb +2 -1
  20. data/lib/ruby_smb/smb1/packet/negotiate_request.rb +2 -5
  21. data/lib/ruby_smb/smb1/packet/negotiate_response.rb +3 -7
  22. data/lib/ruby_smb/smb1/packet/negotiate_response_extended.rb +4 -4
  23. data/lib/ruby_smb/smb1/packet/nt_create_andx_request.rb +2 -4
  24. data/lib/ruby_smb/smb1/packet/nt_create_andx_response.rb +2 -1
  25. data/lib/ruby_smb/smb1/packet/nt_trans/create_request.rb +2 -1
  26. data/lib/ruby_smb/smb1/packet/nt_trans/create_response.rb +2 -1
  27. data/lib/ruby_smb/smb1/packet/nt_trans/request.rb +2 -4
  28. data/lib/ruby_smb/smb1/packet/nt_trans/response.rb +2 -1
  29. data/lib/ruby_smb/smb1/packet/read_andx_request.rb +2 -5
  30. data/lib/ruby_smb/smb1/packet/read_andx_response.rb +2 -1
  31. data/lib/ruby_smb/smb1/packet/session_setup_legacy_request.rb +2 -1
  32. data/lib/ruby_smb/smb1/packet/session_setup_legacy_response.rb +2 -1
  33. data/lib/ruby_smb/smb1/packet/session_setup_request.rb +2 -5
  34. data/lib/ruby_smb/smb1/packet/session_setup_response.rb +2 -1
  35. data/lib/ruby_smb/smb1/packet/trans/peek_nmpipe_request.rb +0 -1
  36. data/lib/ruby_smb/smb1/packet/trans/peek_nmpipe_response.rb +3 -2
  37. data/lib/ruby_smb/smb1/packet/trans/request.rb +2 -5
  38. data/lib/ruby_smb/smb1/packet/trans/response.rb +2 -1
  39. data/lib/ruby_smb/smb1/packet/trans/transact_nmpipe_request.rb +1 -1
  40. data/lib/ruby_smb/smb1/packet/trans/transact_nmpipe_response.rb +1 -1
  41. data/lib/ruby_smb/smb1/packet/trans2/find_first2_request.rb +2 -1
  42. data/lib/ruby_smb/smb1/packet/trans2/find_first2_response.rb +8 -2
  43. data/lib/ruby_smb/smb1/packet/trans2/find_next2_request.rb +2 -1
  44. data/lib/ruby_smb/smb1/packet/trans2/find_next2_response.rb +8 -2
  45. data/lib/ruby_smb/smb1/packet/trans2/open2_request.rb +2 -1
  46. data/lib/ruby_smb/smb1/packet/trans2/open2_response.rb +2 -1
  47. data/lib/ruby_smb/smb1/packet/trans2/request.rb +2 -4
  48. data/lib/ruby_smb/smb1/packet/trans2/request_secondary.rb +2 -4
  49. data/lib/ruby_smb/smb1/packet/trans2/response.rb +2 -1
  50. data/lib/ruby_smb/smb1/packet/trans2/set_file_information_request.rb +2 -1
  51. data/lib/ruby_smb/smb1/packet/trans2/set_file_information_response.rb +2 -1
  52. data/lib/ruby_smb/smb1/packet/tree_connect_request.rb +2 -4
  53. data/lib/ruby_smb/smb1/packet/tree_connect_response.rb +13 -3
  54. data/lib/ruby_smb/smb1/packet/tree_disconnect_request.rb +2 -4
  55. data/lib/ruby_smb/smb1/packet/tree_disconnect_response.rb +2 -1
  56. data/lib/ruby_smb/smb1/packet/write_andx_request.rb +2 -5
  57. data/lib/ruby_smb/smb1/packet/write_andx_response.rb +2 -1
  58. data/lib/ruby_smb/smb1/pipe.rb +8 -3
  59. data/lib/ruby_smb/smb1/tree.rb +40 -2
  60. data/lib/ruby_smb/smb2/dcerpc.rb +7 -2
  61. data/lib/ruby_smb/smb2/file.rb +97 -1
  62. data/lib/ruby_smb/smb2/packet/close_request.rb +2 -4
  63. data/lib/ruby_smb/smb2/packet/close_response.rb +2 -1
  64. data/lib/ruby_smb/smb2/packet/create_request.rb +2 -4
  65. data/lib/ruby_smb/smb2/packet/create_response.rb +2 -1
  66. data/lib/ruby_smb/smb2/packet/echo_request.rb +2 -4
  67. data/lib/ruby_smb/smb2/packet/echo_response.rb +2 -1
  68. data/lib/ruby_smb/smb2/packet/error_packet.rb +7 -0
  69. data/lib/ruby_smb/smb2/packet/ioctl_request.rb +2 -5
  70. data/lib/ruby_smb/smb2/packet/ioctl_response.rb +2 -1
  71. data/lib/ruby_smb/smb2/packet/logoff_request.rb +2 -4
  72. data/lib/ruby_smb/smb2/packet/logoff_response.rb +2 -1
  73. data/lib/ruby_smb/smb2/packet/negotiate_request.rb +2 -5
  74. data/lib/ruby_smb/smb2/packet/negotiate_response.rb +2 -1
  75. data/lib/ruby_smb/smb2/packet/query_directory_request.rb +2 -4
  76. data/lib/ruby_smb/smb2/packet/query_directory_response.rb +8 -2
  77. data/lib/ruby_smb/smb2/packet/read_request.rb +2 -4
  78. data/lib/ruby_smb/smb2/packet/read_response.rb +2 -1
  79. data/lib/ruby_smb/smb2/packet/session_setup_request.rb +2 -5
  80. data/lib/ruby_smb/smb2/packet/session_setup_response.rb +2 -1
  81. data/lib/ruby_smb/smb2/packet/set_info_request.rb +2 -4
  82. data/lib/ruby_smb/smb2/packet/set_info_response.rb +2 -1
  83. data/lib/ruby_smb/smb2/packet/tree_connect_request.rb +2 -5
  84. data/lib/ruby_smb/smb2/packet/tree_connect_response.rb +8 -2
  85. data/lib/ruby_smb/smb2/packet/tree_disconnect_request.rb +2 -4
  86. data/lib/ruby_smb/smb2/packet/tree_disconnect_response.rb +2 -1
  87. data/lib/ruby_smb/smb2/packet/write_request.rb +2 -4
  88. data/lib/ruby_smb/smb2/packet/write_response.rb +2 -1
  89. data/lib/ruby_smb/smb2/pipe.rb +9 -9
  90. data/lib/ruby_smb/smb2/tree.rb +44 -6
  91. data/lib/ruby_smb/version.rb +1 -1
  92. data/spec/lib/ruby_smb/client_spec.rb +123 -11
  93. data/spec/lib/ruby_smb/generic_packet_spec.rb +52 -4
  94. data/spec/lib/ruby_smb/smb1/file_spec.rb +182 -1
  95. data/spec/lib/ruby_smb/smb1/packet/{error_packet_spec.rb → empty_packet_spec.rb} +21 -0
  96. data/spec/lib/ruby_smb/smb1/packet/trans2/find_first2_response_spec.rb +11 -2
  97. data/spec/lib/ruby_smb/smb1/packet/trans2/find_next2_response_spec.rb +11 -2
  98. data/spec/lib/ruby_smb/smb1/packet/tree_connect_response_spec.rb +40 -0
  99. data/spec/lib/ruby_smb/smb1/pipe_spec.rb +63 -2
  100. data/spec/lib/ruby_smb/smb1/tree_spec.rb +44 -7
  101. data/spec/lib/ruby_smb/smb2/file_spec.rb +295 -2
  102. data/spec/lib/ruby_smb/smb2/packet/error_packet_spec.rb +51 -0
  103. data/spec/lib/ruby_smb/smb2/packet/query_directory_response_spec.rb +8 -0
  104. data/spec/lib/ruby_smb/smb2/packet/tree_connect_response_spec.rb +8 -0
  105. data/spec/lib/ruby_smb/smb2/pipe_spec.rb +69 -3
  106. data/spec/lib/ruby_smb/smb2/tree_spec.rb +214 -0
  107. metadata +6 -4
  108. metadata.gz.sig +0 -0
@@ -76,14 +76,19 @@ module RubySMB
76
76
  # Closes the handle to the remote file.
77
77
  #
78
78
  # @return [WindowsError::ErrorCode] the NTStatus code returned by the operation
79
- # @raise [RubySMB::Error::InvalidPacket] if the response command is not SMB_COM_CLOSE
79
+ # @raise [RubySMB::Error::InvalidPacket] if the response packet is not valid
80
80
  # @raise [RubySMB::Error::UnexpectedStatusCode] if the response NTStatus is not STATUS_SUCCESS
81
81
  def close
82
82
  close_request = set_header_fields(RubySMB::SMB1::Packet::CloseRequest.new)
83
83
  raw_response = @tree.client.send_recv(close_request)
84
84
  response = RubySMB::SMB1::Packet::CloseResponse.read(raw_response)
85
- unless response.smb_header.command == RubySMB::SMB1::Commands::SMB_COM_CLOSE
86
- raise RubySMB::Error::InvalidPacket, 'Not a CloseResponse packet'
85
+ unless response.valid?
86
+ raise RubySMB::Error::InvalidPacket.new(
87
+ expected_proto: RubySMB::SMB1::SMB_PROTOCOL_ID,
88
+ expected_cmd: RubySMB::SMB1::Packet::CloseResponse::COMMAND,
89
+ received_proto: response.smb_header.protocol,
90
+ received_cmd: response.smb_header.command
91
+ )
87
92
  end
88
93
  unless response.status_code == WindowsError::NTStatus::STATUS_SUCCESS
89
94
  raise RubySMB::Error::UnexpectedStatusCode, response.status_code.name
@@ -98,7 +103,7 @@ module RubySMB
98
103
  # @param bytes [Integer] the number of bytes to read
99
104
  # @param offset [Integer] the byte offset in the file to start reading from
100
105
  # @return [String] the data read from the file
101
- # @raise [RubySMB::Error::InvalidPacket] if the response command is not SMB_COM_READ_ANDX
106
+ # @raise [RubySMB::Error::InvalidPacket] if the response packet is not valid
102
107
  # @raise [RubySMB::Error::UnexpectedStatusCode] if the response NTStatus is not STATUS_SUCCESS
103
108
  def read(bytes: @size, offset: 0)
104
109
  atomic_read_size = if bytes > @tree.client.max_buffer_size
@@ -113,8 +118,13 @@ module RubySMB
113
118
  read_request = read_packet(read_length: atomic_read_size, offset: offset)
114
119
  raw_response = @tree.client.send_recv(read_request)
115
120
  response = RubySMB::SMB1::Packet::ReadAndxResponse.read(raw_response)
116
- unless response.smb_header.command == RubySMB::SMB1::Commands::SMB_COM_READ_ANDX
117
- raise RubySMB::Error::InvalidPacket, 'Not a ReadAndxResponse packet'
121
+ unless response.valid?
122
+ raise RubySMB::Error::InvalidPacket.new(
123
+ expected_proto: RubySMB::SMB1::SMB_PROTOCOL_ID,
124
+ expected_cmd: RubySMB::SMB1::Packet::ReadAndxResponse::COMMAND,
125
+ received_proto: response.smb_header.protocol,
126
+ received_cmd: response.smb_header.command
127
+ )
118
128
  end
119
129
  unless response.status_code == WindowsError::NTStatus::STATUS_SUCCESS
120
130
  raise RubySMB::Error::UnexpectedStatusCode, response.status_code.name
@@ -149,12 +159,20 @@ module RubySMB
149
159
  read_request.parameter_block.offset = offset
150
160
  read_request
151
161
  end
152
-
162
+
153
163
  def send_recv_read(read_length: 0, offset: 0)
154
164
  read_request = read_packet(read_length: read_length, offset: offset)
155
165
  raw_response = tree.client.send_recv(read_request)
156
166
 
157
167
  response = RubySMB::SMB1::Packet::ReadAndxResponse.read(raw_response)
168
+ unless response.valid?
169
+ raise RubySMB::Error::InvalidPacket.new(
170
+ expected_proto: RubySMB::SMB1::SMB_PROTOCOL_ID,
171
+ expected_cmd: RubySMB::SMB1::Packet::ReadAndxResponse::COMMAND,
172
+ received_proto: response.smb_header.protocol,
173
+ received_cmd: response.smb_header.command
174
+ )
175
+ end
158
176
  unless response.status_code == WindowsError::NTStatus::STATUS_SUCCESS
159
177
  raise RubySMB::Error::UnexpectedStatusCode, response.status_code.name
160
178
  end
@@ -165,9 +183,18 @@ module RubySMB
165
183
  # Delete a file on close
166
184
  #
167
185
  # @return [WindowsError::ErrorCode] the NTStatus Response code
186
+ # @raise [RubySMB::Error::InvalidPacket] if the response packet is not valid
168
187
  def delete
169
188
  raw_response = @tree.client.send_recv(delete_packet)
170
189
  response = RubySMB::SMB1::Packet::Trans2::SetFileInformationResponse.read(raw_response)
190
+ unless response.valid?
191
+ raise RubySMB::Error::InvalidPacket.new(
192
+ expected_proto: RubySMB::SMB1::SMB_PROTOCOL_ID,
193
+ expected_cmd: RubySMB::SMB1::Packet::Trans2::SetFileInformationResponse::COMMAND,
194
+ received_proto: response.smb_header.protocol,
195
+ received_cmd: response.smb_header.command
196
+ )
197
+ end
171
198
  response.status_code
172
199
  end
173
200
 
@@ -190,7 +217,7 @@ module RubySMB
190
217
  # @param data [String] the data to write to the file
191
218
  # @param offset [Integer] the offset in the file to start writing from
192
219
  # @return [Integer] the count of bytes written
193
- # @raise [RubySMB::Error::InvalidPacket] if the response command is not SMB_COM_WRITE_ANDX
220
+ # @raise [RubySMB::Error::InvalidPacket] if the response packet is not valid
194
221
  # @raise [RubySMB::Error::UnexpectedStatusCode] if the response NTStatus is not STATUS_SUCCESS
195
222
  def write(data:, offset: 0)
196
223
  buffer = data.dup
@@ -206,8 +233,13 @@ module RubySMB
206
233
  write_request = write_packet(data: buffer.slice!(0, atomic_write_size), offset: offset)
207
234
  raw_response = @tree.client.send_recv(write_request)
208
235
  response = RubySMB::SMB1::Packet::WriteAndxResponse.read(raw_response)
209
- unless response.smb_header.command == RubySMB::SMB1::Commands::SMB_COM_WRITE_ANDX
210
- raise RubySMB::Error::InvalidPacket, 'Not a WriteAndxResponse packet'
236
+ unless response.valid?
237
+ raise RubySMB::Error::InvalidPacket.new(
238
+ expected_proto: RubySMB::SMB1::SMB_PROTOCOL_ID,
239
+ expected_cmd: RubySMB::SMB1::Packet::WriteAndxResponse::COMMAND,
240
+ received_proto: response.smb_header.protocol,
241
+ received_cmd: response.smb_header.command
242
+ )
211
243
  end
212
244
  unless response.status_code == WindowsError::NTStatus::STATUS_SUCCESS
213
245
  raise RubySMB::Error::UnexpectedStatusCode, response.status_code.name
@@ -235,12 +267,20 @@ module RubySMB
235
267
  write_request.parameter_block.remaining = write_request.parameter_block.data_length
236
268
  write_request
237
269
  end
238
-
270
+
239
271
  def send_recv_write(data:'', offset: 0)
240
272
  pkt = write_packet(data: data, offset: offset)
241
273
  pkt.set_64_bit_offset(true)
242
274
  raw_response = @tree.client.send_recv(pkt)
243
275
  response = RubySMB::SMB1::Packet::WriteAndxResponse.read(raw_response)
276
+ unless response.valid?
277
+ raise RubySMB::Error::InvalidPacket.new(
278
+ expected_proto: RubySMB::SMB1::SMB_PROTOCOL_ID,
279
+ expected_cmd: RubySMB::SMB1::Packet::WriteAndxResponse::COMMAND,
280
+ received_proto: response.smb_header.protocol,
281
+ received_cmd: response.smb_header.command
282
+ )
283
+ end
244
284
  response.parameter_block.count_low
245
285
  end
246
286
 
@@ -248,9 +288,18 @@ module RubySMB
248
288
  #
249
289
  # @param new_file_name [String] the new name
250
290
  # @return [WindowsError::ErrorCode] the NTStatus Response code
291
+ # @raise [RubySMB::Error::InvalidPacket] if the response packet is not valid
251
292
  def rename(new_file_name)
252
293
  raw_response = tree.client.send_recv(rename_packet(new_file_name))
253
294
  response = RubySMB::SMB1::Packet::Trans2::SetFileInformationResponse.read(raw_response)
295
+ unless response.valid?
296
+ raise RubySMB::Error::InvalidPacket.new(
297
+ expected_proto: RubySMB::SMB1::SMB_PROTOCOL_ID,
298
+ expected_cmd: RubySMB::SMB1::Packet::Trans2::SetFileInformationResponse::COMMAND,
299
+ received_proto: response.smb_header.protocol,
300
+ received_cmd: response.smb_header.command
301
+ )
302
+ end
254
303
  response.status_code
255
304
  end
256
305
 
@@ -4,6 +4,8 @@ module RubySMB
4
4
  # A SMB1 SMB_COM_CLOSE Request Packet as defined in
5
5
  # [2.2.4.5.1 Request](https://msdn.microsoft.com/en-us/library/ee442151.aspx)
6
6
  class CloseRequest < RubySMB::GenericPacket
7
+ COMMAND = RubySMB::SMB1::Commands::SMB_COM_CLOSE
8
+
7
9
  # A SMB1 Parameter Block as defined by the {CloseRequest}
8
10
  class ParameterBlock < RubySMB::SMB1::ParameterBlock
9
11
  endian :little
@@ -20,11 +22,6 @@ module RubySMB
20
22
  parameter_block :parameter_block
21
23
  data_block :data_block
22
24
 
23
- def initialize_instance
24
- super
25
- smb_header.command = RubySMB::SMB1::Commands::SMB_COM_CLOSE
26
- end
27
-
28
25
  end
29
26
  end
30
27
  end
@@ -4,6 +4,8 @@ module RubySMB
4
4
  # A SMB1 SMB_COM_CLOSE Response Packet as defined in
5
5
  # [2.2.4.5.2 Response](https://msdn.microsoft.com/en-us/library/ee441667.aspx)
6
6
  class CloseResponse < RubySMB::GenericPacket
7
+ COMMAND = RubySMB::SMB1::Commands::SMB_COM_CLOSE
8
+
7
9
  # A SMB1 Parameter Block as defined by the {CloseResponse}
8
10
  class ParameterBlock < RubySMB::SMB1::ParameterBlock
9
11
  end
@@ -18,7 +20,6 @@ module RubySMB
18
20
 
19
21
  def initialize_instance
20
22
  super
21
- smb_header.command = RubySMB::SMB1::Commands::SMB_COM_CLOSE
22
23
  smb_header.flags.reply = 1
23
24
  end
24
25
 
@@ -4,6 +4,8 @@ module RubySMB
4
4
  # This class represents an SMB1 Echo Request Packet as defined in
5
5
  # [2.2.4.39.1 Request](https://msdn.microsoft.com/en-us/library/ee441746.aspx)
6
6
  class EchoRequest < RubySMB::GenericPacket
7
+ COMMAND = RubySMB::SMB1::Commands::SMB_COM_ECHO
8
+
7
9
  # The {RubySMB::SMB1::ParameterBlock} specific to this packet type.
8
10
  class ParameterBlock < RubySMB::SMB1::ParameterBlock
9
11
  uint16 :echo_count, label: 'Echo Count', initial_value: 1
@@ -18,10 +20,6 @@ module RubySMB
18
20
  parameter_block :parameter_block
19
21
  data_block :data_block
20
22
 
21
- def initialize_instance
22
- super
23
- smb_header.command = RubySMB::SMB1::Commands::SMB_COM_ECHO
24
- end
25
23
  end
26
24
  end
27
25
  end
@@ -4,6 +4,8 @@ module RubySMB
4
4
  # This class represents an SMB1 Echo Request Packet as defined in
5
5
  # [2.2.4.39.2 Response](https://msdn.microsoft.com/en-us/library/ee441626.aspx)
6
6
  class EchoResponse < RubySMB::GenericPacket
7
+ COMMAND = RubySMB::SMB1::Commands::SMB_COM_ECHO
8
+
7
9
  # The {RubySMB::SMB1::ParameterBlock} specific to this packet type.
8
10
  class ParameterBlock < RubySMB::SMB1::ParameterBlock
9
11
  uint16 :sequence_number, label: 'Sequence Number'
@@ -20,7 +22,6 @@ module RubySMB
20
22
 
21
23
  def initialize_instance
22
24
  super
23
- smb_header.command = RubySMB::SMB1::Commands::SMB_COM_ECHO
24
25
  smb_header.flags.reply = 1
25
26
  end
26
27
  end
@@ -4,9 +4,16 @@ module RubySMB
4
4
  # This packet represent an SMB1 Response Packet when the parameter and
5
5
  # data blocks will be empty.
6
6
  class EmptyPacket < RubySMB::GenericPacket
7
+ attr_accessor :original_command
8
+
7
9
  smb_header :smb_header
8
10
  parameter_block :parameter_block
9
11
  data_block :data_block
12
+
13
+ def valid?
14
+ return smb_header.protocol == RubySMB::SMB1::SMB_PROTOCOL_ID &&
15
+ smb_header.command == @original_command
16
+ end
10
17
  end
11
18
  end
12
19
  end
@@ -4,6 +4,8 @@ module RubySMB
4
4
  # This class represents an SMB1 LOGOFF Request Packet as defined in
5
5
  # [2.2.4.54.1 Request](https://msdn.microsoft.com/en-us/library/ee442167.aspx)
6
6
  class LogoffRequest < RubySMB::GenericPacket
7
+ COMMAND = RubySMB::SMB1::Commands::SMB_COM_LOGOFF
8
+
7
9
  # The Parameter Block for this packet is empty save the Word Count and ANDX Block
8
10
  class ParameterBlock < RubySMB::SMB1::ParameterBlock
9
11
  and_x_block :andx_block
@@ -17,10 +19,6 @@ module RubySMB
17
19
  parameter_block :parameter_block
18
20
  data_block :data_block
19
21
 
20
- def initialize_instance
21
- super
22
- smb_header.command = RubySMB::SMB1::Commands::SMB_COM_LOGOFF
23
- end
24
22
  end
25
23
  end
26
24
  end
@@ -4,6 +4,8 @@ module RubySMB
4
4
  # This class represents an SMB1 LOGOFF Response Packet as defined in
5
5
  # [2.2.4.54.2 Response](https://msdn.microsoft.com/en-us/library/ee441488.aspx)
6
6
  class LogoffResponse < RubySMB::GenericPacket
7
+ COMMAND = RubySMB::SMB1::Commands::SMB_COM_LOGOFF
8
+
7
9
  # The Parameter Block for this packet is empty save the Word Count and ANDX Block
8
10
  class ParameterBlock < RubySMB::SMB1::ParameterBlock
9
11
  and_x_block :andx_block
@@ -19,7 +21,6 @@ module RubySMB
19
21
 
20
22
  def initialize_instance
21
23
  super
22
- smb_header.command = RubySMB::SMB1::Commands::SMB_COM_LOGOFF
23
24
  smb_header.flags.reply = 1
24
25
  end
25
26
  end
@@ -4,6 +4,8 @@ module RubySMB
4
4
  # A SMB1 SMB_COM_NEGOTIATE Request Packet as defined in
5
5
  # [2.2.4.52.1](https://msdn.microsoft.com/en-us/library/ee441572.aspx)
6
6
  class NegotiateRequest < RubySMB::GenericPacket
7
+ COMMAND = RubySMB::SMB1::Commands::SMB_COM_NEGOTIATE
8
+
7
9
  # Represents the specific layout of the DataBlock for a NegotiateRequest Packet.
8
10
  class DataBlock < RubySMB::SMB1::DataBlock
9
11
  array :dialects, label: 'Dialects', type: :dialect, read_until: :eof
@@ -13,11 +15,6 @@ module RubySMB
13
15
  parameter_block :parameter_block
14
16
  data_block :data_block
15
17
 
16
- def initialize_instance
17
- super
18
- smb_header.command = RubySMB::SMB1::Commands::SMB_COM_NEGOTIATE
19
- end
20
-
21
18
  # Add an individual Dialect string to the list of
22
19
  # Dialects in the packet.
23
20
  #
@@ -4,6 +4,8 @@ module RubySMB
4
4
  # A SMB1 SMB_COM_NEGOTIATE Non-Extended Security Response Packet as defined in
5
5
  # [2.2.4.5.2.2 Non-Extended Security Response](https://msdn.microsoft.com/en-us/library/cc246327.aspx)
6
6
  class NegotiateResponse < RubySMB::GenericPacket
7
+ COMMAND = RubySMB::SMB1::Commands::SMB_COM_NEGOTIATE
8
+
7
9
  # An SMB_Parameters Block as defined by the {NegotiateResponse}.
8
10
  class ParameterBlock < RubySMB::SMB1::ParameterBlock
9
11
  uint16 :dialect_index, label: 'Dialect Index'
@@ -32,13 +34,7 @@ module RubySMB
32
34
 
33
35
  def initialize_instance
34
36
  super
35
- header = smb_header
36
- header.command = RubySMB::SMB1::Commands::SMB_COM_NEGOTIATE
37
- header.flags.reply = 1
38
- end
39
-
40
- def valid?
41
- smb_header.command == RubySMB::SMB1::Commands::SMB_COM_NEGOTIATE
37
+ smb_header.flags.reply = 1
42
38
  end
43
39
 
44
40
  # Stores the list of {RubySMB::SMB1::Dialect} that were sent to the
@@ -4,6 +4,8 @@ module RubySMB
4
4
  # A SMB1 SMB_COM_NEGOTIATE Extended Security Response Packet as defined in
5
5
  # [2.2.4.5.2.1 Extended Security Response](https://msdn.microsoft.com/en-us/library/cc246326.aspx)
6
6
  class NegotiateResponseExtended < RubySMB::GenericPacket
7
+ COMMAND = RubySMB::SMB1::Commands::SMB_COM_NEGOTIATE
8
+
7
9
  # An SMB_Parameters Block as defined by the {NegotiateResponseExtended}.
8
10
  class ParameterBlock < RubySMB::SMB1::ParameterBlock
9
11
  uint16 :dialect_index, label: 'Dialect Index'
@@ -31,13 +33,11 @@ module RubySMB
31
33
 
32
34
  def initialize_instance
33
35
  super
34
- header = smb_header
35
- header.command = RubySMB::SMB1::Commands::SMB_COM_NEGOTIATE
36
- header.flags.reply = 1
36
+ smb_header.flags.reply = 1
37
37
  end
38
38
 
39
39
  def valid?
40
- return false unless smb_header.command == RubySMB::SMB1::Commands::SMB_COM_NEGOTIATE
40
+ return false unless super
41
41
  return false unless parameter_block.capabilities.extended_security == 1
42
42
  true
43
43
  end
@@ -5,6 +5,8 @@ module RubySMB
5
5
  # [2.2.4.64.1 Request](https://msdn.microsoft.com/en-us/library/ee442175.aspx) and
6
6
  # [2.2.4.9.1 Client Request Extensions](https://msdn.microsoft.com/en-us/library/cc246332.aspx)
7
7
  class NtCreateAndxRequest < RubySMB::GenericPacket
8
+ COMMAND = RubySMB::SMB1::Commands::SMB_COM_NT_CREATE_ANDX
9
+
8
10
  # A SMB1 Parameter Block as defined by the {NtCreateAndxRequest}
9
11
  class ParameterBlock < RubySMB::SMB1::ParameterBlock
10
12
  endian :little
@@ -52,10 +54,6 @@ module RubySMB
52
54
  parameter_block :parameter_block
53
55
  data_block :data_block
54
56
 
55
- def initialize_instance
56
- super
57
- smb_header.command = RubySMB::SMB1::Commands::SMB_COM_NT_CREATE_ANDX
58
- end
59
57
  end
60
58
  end
61
59
  end
@@ -5,6 +5,8 @@ module RubySMB
5
5
  # [2.2.4.64.2 Response](https://msdn.microsoft.com/en-us/library/ee441612.aspx) and
6
6
  # [2.2.4.9.2 Server Response Extensions](https://msdn.microsoft.com/en-us/library/cc246334.aspx)
7
7
  class NtCreateAndxResponse < RubySMB::GenericPacket
8
+ COMMAND = RubySMB::SMB1::Commands::SMB_COM_NT_CREATE_ANDX
9
+
8
10
  # A SMB1 Parameter Block as defined by the {NtCreateAndxResponse}
9
11
  class ParameterBlock < RubySMB::SMB1::ParameterBlock
10
12
  endian :little
@@ -57,7 +59,6 @@ module RubySMB
57
59
 
58
60
  def initialize_instance
59
61
  super
60
- smb_header.command = RubySMB::SMB1::Commands::SMB_COM_NT_CREATE_ANDX
61
62
  smb_header.flags.reply = 1
62
63
  end
63
64
  end
@@ -5,6 +5,8 @@ module RubySMB
5
5
  # Class representing a generic NT Transaction request packet as defined in
6
6
  # [2.2.4.62.1 Request](https://msdn.microsoft.com/en-us/library/ee441534.aspx)
7
7
  class CreateRequest < RubySMB::GenericPacket
8
+ COMMAND = RubySMB::SMB1::Commands::SMB_COM_NT_TRANSACT
9
+
8
10
  class ParameterBlock < RubySMB::SMB1::Packet::NtTrans::Request::ParameterBlock
9
11
  end
10
12
 
@@ -81,7 +83,6 @@ module RubySMB
81
83
 
82
84
  def initialize_instance
83
85
  super
84
- smb_header.command = RubySMB::SMB1::Commands::SMB_COM_NT_TRANSACT
85
86
  parameter_block.function = RubySMB::SMB1::Packet::NtTrans::Subcommands::CREATE
86
87
  end
87
88
  end
@@ -5,6 +5,8 @@ module RubySMB
5
5
  # Class representing a NT Transaction Create response packet as defined in
6
6
  # [2.2.7.1.2 Response](https://msdn.microsoft.com/en-us/library/ee441961.aspx)
7
7
  class CreateResponse < RubySMB::GenericPacket
8
+ COMMAND = RubySMB::SMB1::Commands::SMB_COM_NT_TRANSACT
9
+
8
10
  class ParameterBlock < RubySMB::SMB1::Packet::NtTrans::Response::ParameterBlock
9
11
  end
10
12
 
@@ -49,7 +51,6 @@ module RubySMB
49
51
 
50
52
  def initialize_instance
51
53
  super
52
- smb_header.command = RubySMB::SMB1::Commands::SMB_COM_NT_TRANSACT
53
54
  smb_header.flags.reply = 1
54
55
  end
55
56
  end
@@ -5,6 +5,8 @@ module RubySMB
5
5
  # Class representing a generic NT Transaction request packet as defined in
6
6
  # [2.2.4.62.1 Request](https://msdn.microsoft.com/en-us/library/ee441534.aspx)
7
7
  class Request < RubySMB::GenericPacket
8
+ COMMAND = RubySMB::SMB1::Commands::SMB_COM_NT_TRANSACT
9
+
8
10
  # The {RubySMB::SMB1::ParameterBlock} specific to this packet type.
9
11
  class ParameterBlock < RubySMB::SMB1::ParameterBlock
10
12
  endian :little
@@ -36,10 +38,6 @@ module RubySMB
36
38
  parameter_block :parameter_block
37
39
  data_block :data_block
38
40
 
39
- def initialize_instance
40
- super
41
- smb_header.command = RubySMB::SMB1::Commands::SMB_COM_NT_TRANSACT
42
- end
43
41
  end
44
42
  end
45
43
  end
@@ -5,6 +5,8 @@ module RubySMB
5
5
  # Class representing a generic NT Transaction response packet as defined in
6
6
  # [2.2.4.62.2 Response](https://msdn.microsoft.com/en-us/library/ee442112.aspx)
7
7
  class Response < RubySMB::GenericPacket
8
+ COMMAND = RubySMB::SMB1::Commands::SMB_COM_NT_TRANSACT
9
+
8
10
  # The {RubySMB::SMB1::ParameterBlock} specific to this packet type.
9
11
  class ParameterBlock < RubySMB::SMB1::ParameterBlock
10
12
  endian :little
@@ -34,7 +36,6 @@ module RubySMB
34
36
 
35
37
  def initialize_instance
36
38
  super
37
- smb_header.command = RubySMB::SMB1::Commands::SMB_COM_NT_TRANSACT
38
39
  smb_header.flags.reply = 1
39
40
  end
40
41
  end