Class: Rex::Proto::MsNrtp::Client

Inherits:
Object
  • Object
show all
Includes:
Rex::Proto::MsNrtp
Defined in:
lib/rex/proto/ms_nrtp/client.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(host, port, resource, context: {}, ssl: false, ssl_version: nil, comm: nil, timeout: 10) ⇒ Client

Returns a new instance of Client.

Parameters:

  • host (String)

    The MS-NRTP server host.

  • port (Integer, NilClass)

    The MS-NRTP server port or nil for automatic based on ssl.

  • ssl (Boolean) (defaults to: false)

    Whether or not SSL is used for the connection.

  • ssl_version (String) (defaults to: nil)

    The SSL version to use.

  • comm (Rex::Socket::Comm) (defaults to: nil)

    An optional, explicit object to use for creating the connection.

  • timeout (Integer) (defaults to: 10)

    The communication timeout in seconds.



33
34
35
36
37
38
39
40
41
42
# File 'lib/rex/proto/ms_nrtp/client.rb', line 33

def initialize(host, port, resource, context: {}, ssl: false, ssl_version: nil, comm: nil, timeout: 10)
  @host = host
  @port = port
  @resource = resource
  @context = context
  @ssl = ssl
  @ssl_version = ssl_version
  @comm = comm
  @timeout = timeout
end

Instance Attribute Details

#commRex::Socket::Comm (readonly)

Returns An optional, explicit object to use for creating the connection.

Returns:

  • (Rex::Socket::Comm)

    An optional, explicit object to use for creating the connection.



21
22
23
# File 'lib/rex/proto/ms_nrtp/client.rb', line 21

def comm
  @comm
end

#hostString (readonly)

Returns The MS-NRTP server host.

Returns:

  • (String)

    The MS-NRTP server host.



9
10
11
# File 'lib/rex/proto/ms_nrtp/client.rb', line 9

def host
  @host
end

#portInteger (readonly)

Returns The S-NRTP server port.

Returns:

  • (Integer)

    The S-NRTP server port.



12
13
14
# File 'lib/rex/proto/ms_nrtp/client.rb', line 12

def port
  @port
end

#resourceString (readonly)

Returns The server resource component of the URI string.

Returns:

  • (String)

    The server resource component of the URI string.



15
16
17
# File 'lib/rex/proto/ms_nrtp/client.rb', line 15

def resource
  @resource
end

#sslBoolean (readonly)

Returns Whether or not SSL is used for the connection.

Returns:

  • (Boolean)

    Whether or not SSL is used for the connection.



18
19
20
# File 'lib/rex/proto/ms_nrtp/client.rb', line 18

def ssl
  @ssl
end

#timeoutInteger

Returns The communication timeout in seconds.

Returns:

  • (Integer)

    The communication timeout in seconds.



25
26
27
# File 'lib/rex/proto/ms_nrtp/client.rb', line 25

def timeout
  @timeout
end

Instance Method Details

#closeNilClass

Close the connection to the remote server.

Returns:

  • (NilClass)


67
68
69
70
71
72
73
74
# File 'lib/rex/proto/ms_nrtp/client.rb', line 67

def close
  if @conn && !@conn.closed?
    @conn.shutdown
    @conn.close
  end

  @conn = nil
end

#connect(t = -1)) ⇒ NilClass

Establish the connection to the remote server.

Parameters:

  • t (Integer) (defaults to: -1))

    An explicit timeout to use for the connection otherwise the default will be used.

Returns:

  • (NilClass)


48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/rex/proto/ms_nrtp/client.rb', line 48

def connect(t = -1)
  timeout = (t.nil? or t == -1) ? @timeout : t

  @conn = Rex::Socket::Tcp.create(
    'PeerHost'   => @host,
    'PeerPort'   => @port.to_i,
    'Context'    => @context,
    'SSL'        => @ssl,
    'SSLVersion' => @ssl_version,
    'Timeout'    => timeout,
    'Comm'       => @comm
  )

  nil
end

#recvObject



76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
# File 'lib/rex/proto/ms_nrtp/client.rb', line 76

def recv
  remaining = @timeout
  message, elapsed_time = Rex::Stopwatch.elapsed_time do
    ::Timeout.timeout(remaining) do
      MsNrtpMessage.read(@conn)
    end
  end
  return nil unless message.operation_type == Enums::OperationTypeEnum[:Reply] && message.content_length?

  remaining -= elapsed_time
  body = ''
  while body.length < message.content_length
    chunk, elapsed_time = Rex::Stopwatch.elapsed_time do
      @conn.read(message.content_length - body.length, remaining)
    end
    remaining -= elapsed_time
    body << chunk
  end

  body
end

#send(data, content_type) ⇒ Object



98
99
100
101
102
103
104
105
106
107
108
# File 'lib/rex/proto/ms_nrtp/client.rb', line 98

def send(data, content_type)
  message = MsNrtpMessage.new(
    content_length: data.length,
    headers: [
      { token: MsNrtpHeader::MsNrtpHeaderUri::TOKEN, header: { uri_value: "tcp://#{Rex::Socket.to_authority(@host, @port)}/#{@resource}" } },
      { token: MsNrtpHeader::MsNrtpHeaderContentType::TOKEN, header: { content_type_value: content_type } },
      { token: MsNrtpHeader::MsNrtpHeaderEnd::TOKEN }
    ]
  )
  @conn.put(message.to_binary_s + data)
end

#send_binary(serialized_stream) ⇒ Object



115
116
117
# File 'lib/rex/proto/ms_nrtp/client.rb', line 115

def send_binary(serialized_stream)
  send(serialized_stream.to_binary_s, 'application/octet-stream'.encode('UTF-8'))
end

#send_recv(data, content_type) ⇒ Object



110
111
112
113
# File 'lib/rex/proto/ms_nrtp/client.rb', line 110

def send_recv(data, content_type)
  send(data, content_type)
  recv
end