Class: Rex::Proto::MsNrtp::Client
- Inherits:
-
Object
- Object
- Rex::Proto::MsNrtp::Client
- Includes:
- Rex::Proto::MsNrtp
- Defined in:
- lib/rex/proto/ms_nrtp/client.rb
Instance Attribute Summary collapse
-
#comm ⇒ Rex::Socket::Comm
readonly
An optional, explicit object to use for creating the connection.
-
#host ⇒ String
readonly
The MS-NRTP server host.
-
#port ⇒ Integer
readonly
The S-NRTP server port.
-
#resource ⇒ String
readonly
The server resource component of the URI string.
-
#ssl ⇒ Boolean
readonly
Whether or not SSL is used for the connection.
-
#timeout ⇒ Integer
The communication timeout in seconds.
Instance Method Summary collapse
-
#close ⇒ NilClass
Close the connection to the remote server.
-
#connect(t = -1)) ⇒ NilClass
Establish the connection to the remote server.
-
#initialize(host, port, resource, context: {}, ssl: false, ssl_version: nil, comm: nil, timeout: 10) ⇒ Client
constructor
A new instance of Client.
- #recv ⇒ Object
- #send(data, content_type) ⇒ Object
- #send_binary(serialized_stream) ⇒ Object
- #send_recv(data, content_type) ⇒ Object
Constructor Details
#initialize(host, port, resource, context: {}, ssl: false, ssl_version: nil, comm: nil, timeout: 10) ⇒ Client
Returns a new instance of Client.
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
#comm ⇒ Rex::Socket::Comm (readonly)
Returns 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 |
#host ⇒ String (readonly)
Returns The MS-NRTP server host.
9 10 11 |
# File 'lib/rex/proto/ms_nrtp/client.rb', line 9 def host @host end |
#port ⇒ Integer (readonly)
Returns The S-NRTP server port.
12 13 14 |
# File 'lib/rex/proto/ms_nrtp/client.rb', line 12 def port @port end |
#resource ⇒ String (readonly)
Returns 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 |
#ssl ⇒ Boolean (readonly)
Returns 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 |
#timeout ⇒ Integer
Returns 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
#close ⇒ NilClass
Close the connection to the remote server.
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.
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 |
#recv ⇒ Object
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 , elapsed_time = Rex::Stopwatch.elapsed_time do ::Timeout.timeout(remaining) do MsNrtpMessage.read(@conn) end end return nil unless .operation_type == Enums::OperationTypeEnum[:Reply] && .content_length? remaining -= elapsed_time body = '' while body.length < .content_length chunk, elapsed_time = Rex::Stopwatch.elapsed_time do @conn.read(.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) = MsNrtpMessage.new( content_length: data.length, headers: [ { token: MsNrtpHeader::MsNrtpHeaderUri::TOKEN, header: { uri_value: "tcp://#{Rex::Socket.(@host, @port)}/#{@resource}" } }, { token: MsNrtpHeader::MsNrtpHeaderContentType::TOKEN, header: { content_type_value: content_type } }, { token: MsNrtpHeader::MsNrtpHeaderEnd::TOKEN } ] ) @conn.put(.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 |