Module: RubySMB::Client::Echo

Included in:
RubySMB::Client
Defined in:
lib/ruby_smb/client/echo.rb

Overview

Contains the methods for doing ECHO commands

Instance Method Summary collapse

Instance Method Details

#smb1_echo(count: 1, data: '') ⇒ RubySMB::SMB1::Packet::EchoResponse

Sends an ECHO request packet and returns the last response packet.

Parameters:

  • echo (Integer)

    the number of times the server should echo (ignored in SMB2)

  • data (String) (defaults to: '')

    the data the server should echo back (ignored in SMB2)

Returns:



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/ruby_smb/client/echo.rb', line 11

def smb1_echo(count: 1, data: '')
  request = RubySMB::SMB1::Packet::EchoRequest.new
  request.parameter_block.echo_count = count
  request.data_block.data = data
  raw_response = send_recv(request)
  (count - 1).times do
    raw_response = dispatcher.recv_packet
  end
  response = RubySMB::SMB1::Packet::EchoResponse.read(raw_response)
  unless response.valid?
    raise RubySMB::Error::InvalidPacket.new(
      expected_proto: RubySMB::SMB1::SMB_PROTOCOL_ID,
      expected_cmd:   RubySMB::SMB1::Packet::EchoResponse::COMMAND,
      packet:         response
    )
  end
  response
end

#smb2_echoRubySMB::SMB2::Packet::EchoResponse

Sends an ECHO request packet and returns the response packet.



34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/ruby_smb/client/echo.rb', line 34

def smb2_echo
  request      = RubySMB::SMB2::Packet::EchoRequest.new
  raw_response = send_recv(request)
  response = RubySMB::SMB2::Packet::EchoResponse.read(raw_response)
  unless response.valid?
    raise RubySMB::Error::InvalidPacket.new(
      expected_proto: RubySMB::SMB2::SMB2_PROTOCOL_ID,
      expected_cmd:   RubySMB::SMB2::Packet::EchoResponse::COMMAND,
      packet:         response
    )
  end
  response
end