Class: Rex::Proto::Nuuo::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/rex/proto/nuuo/client.rb

Overview

This class is a representation of a nuuo client

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(opts = {}) ⇒ Client

Returns a new instance of Client.


43
44
45
46
47
48
49
50
51
52
53
# File 'lib/rex/proto/nuuo/client.rb', line 43

def initialize(opts = {})
  self.host         = opts[:host]
  self.port         = opts[:port] || 5180
  self.timeout      = opts[:timeout] || 10
  self.context      = opts[:context] || {}
  self.username     = opts[:username]
  self.password     = opts[:password]
  self.user_session = opts[:user_session]

  self.config = Nuuo::ClientRequest::DefaultConfig
end

Instance Attribute Details

#configHash

Returns ClientRequest configuration options.

Returns:

  • (Hash)

    ClientRequest configuration options


41
42
43
# File 'lib/rex/proto/nuuo/client.rb', line 41

def config
  @config
end

#connectionIO

Returns The connection established through Rex sockets.

Returns:

  • (IO)

    The connection established through Rex sockets


23
24
25
# File 'lib/rex/proto/nuuo/client.rb', line 23

def connection
  @connection
end

#contextHash

Returns The Msf context where the connection belongs to.

Returns:

  • (Hash)

    The Msf context where the connection belongs to


26
27
28
# File 'lib/rex/proto/nuuo/client.rb', line 26

def context
  @context
end

#hostString

Returns The nuuo server host.

Returns:

  • (String)

    The nuuo server host


14
15
16
# File 'lib/rex/proto/nuuo/client.rb', line 14

def host
  @host
end

#ncs_versionString

Returns NCS version used in session.

Returns:

  • (String)

    NCS version used in session


29
30
31
# File 'lib/rex/proto/nuuo/client.rb', line 29

def ncs_version
  @ncs_version
end

#passwordString

Returns Password for NCS user.

Returns:

  • (String)

    Password for NCS user


35
36
37
# File 'lib/rex/proto/nuuo/client.rb', line 35

def password
  @password
end

#portInteger

Returns The nuuo server port.

Returns:

  • (Integer)

    The nuuo server port


17
18
19
# File 'lib/rex/proto/nuuo/client.rb', line 17

def port
  @port
end

#timeoutInteger

Returns The connect/read timeout.

Returns:

  • (Integer)

    The connect/read timeout


20
21
22
# File 'lib/rex/proto/nuuo/client.rb', line 20

def timeout
  @timeout
end

#user_sessionString

Returns ID for the user session.

Returns:

  • (String)

    ID for the user session


38
39
40
# File 'lib/rex/proto/nuuo/client.rb', line 38

def user_session
  @user_session
end

#usernameString

Returns Username for NCS.

Returns:

  • (String)

    Username for NCS


32
33
34
# File 'lib/rex/proto/nuuo/client.rb', line 32

def username
  @username
end

Instance Method Details

#closeObject

Closes the connection


64
65
66
67
68
69
70
71
# File 'lib/rex/proto/nuuo/client.rb', line 64

def close
  if connection
    connection.shutdown
    connection.close unless connection.closed?
  end

  self.connection = nil
end

#connect(temp: false) ⇒ Rex::Socket::Tcp

Creates a connection through a Rex socket

Returns:

  • (Rex::Socket::Tcp)

58
59
60
61
# File 'lib/rex/proto/nuuo/client.rb', line 58

def connect(temp: false)
  return connection if connection && !temp
  return create_tcp_connection(temp: temp)
end

#read_response(conn = nil, t = -1)) ⇒ Object


82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
# File 'lib/rex/proto/nuuo/client.rb', line 82

def read_response(conn=nil, t=-1)
  res = Response.new
  conn = connection unless conn

  return res if not t
  Timeout.timeout((t < 0) ? nil : t) do
    parse_status = nil
    while (!conn.closed? &&
            parse_status != Response::ParseCode::Completed &&
            parse_status != Response::ParseCode::Error
    )
      begin
        buff = conn.get_once
        parse_status = res.parse(buff || '')
      rescue ::Errno::EPIPE, ::EOFError, ::IOError
        case res.state
        when Response::ParseState::ProcessingHeader
          res = nil
        when Response::ParseState::ProcessingBody
          res.error = :truncated
        end
        break
      end
    end
  end

  res
end

#request_commitconfig(opts = {}) ⇒ ClientRequest

COMMITCONFIG FileName: FileType: 1 Content-Length User-Session-No: <session-no>

<data> filedata

Returns:


171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
# File 'lib/rex/proto/nuuo/client.rb', line 171

def request_commitconfig(opts={})
  opts = self.config.merge(opts)
  opts['headers'] ||= {}
  opts['method'] = 'COMMITCONFIG'

  opts['headers']['FileName'] = opts['file_name']
  opts['headers']['FileType'] = opts['file_type'] || 1

  session = user_session_header(opts)
  opts['headers']['User-Session-No'] = session if session

  opts['data'] = '' unless opts['data']
  opts['headers']['Content-Length'] = opts['data'].length

  ClientRequest.new(opts)
end

#request_getconfig(opts = {}) ⇒ ClientRequest

GETCONFIG FileName: FileType: 1 User-Session-No: <session-no>

Returns:


150
151
152
153
154
155
156
157
158
159
160
161
# File 'lib/rex/proto/nuuo/client.rb', line 150

def request_getconfig(opts={})
  opts = self.config.merge(opts)
  opts['headers'] ||= {}
  opts['method'] = 'GETCONFIG'

  opts['headers']['FileName'] = opts['file_name']
  opts['headers']['FileType'] = opts['file_type'] || 1
  session = user_session_header(opts)
  opts['headers']['User-Session-No'] = session if session

  ClientRequest.new(opts)
end

#request_getopenalarm(opts = {}) ⇒ ClientRequest

GETOPENALARM NUCM/1.0 DeviceID: <number> SourceServer: <server-id> LastOne: <number>

Returns:


233
234
235
236
237
238
239
240
241
242
243
# File 'lib/rex/proto/nuuo/client.rb', line 233

def request_getopenalarm(opts={})
  opts = self.config.merge(opts)
  opts['headers'] ||= {}
  opts['method'] = 'GETOPENALARM'

  opts['headers']['DeviceID'] = opts['device_id'] || 1
  opts['headers']['SourceServer'] = opts['source_server'] || 1
  opts['headers']['LastOne'] = opts['last_one'] || 1

  ClientRequest.new(opts)
end

#request_ping(opts = {}) ⇒ Object


120
121
122
123
124
125
126
127
128
# File 'lib/rex/proto/nuuo/client.rb', line 120

def request_ping(opts={})
  opts = self.config.merge(opts)
  opts['headers'] ||= {}
  opts['method'] = 'PING'
  session = user_session_header(opts)
  opts['headers']['User-Session-No'] = session if session

  ClientRequest.new(opts)
end

#request_sendlicfile(opts = {}) ⇒ Object


130
131
132
133
134
135
136
137
138
139
140
141
142
143
# File 'lib/rex/proto/nuuo/client.rb', line 130

def request_sendlicfile(opts={})
  opts = self.config.merge(opts)
  opts['headers'] ||= {}
  opts['method'] = 'SENDLICFILE'

  session = user_session_header(opts)
  opts['headers']['User-Session-No'] = session if session
  opts['data'] = '' unless opts['data']

  opts['headers']['FileName'] = opts['file_name']
  opts['headers']['Content-Length'] = opts['data'].length

  ClientRequest.new(opts)
end

#request_userlogin(opts = {}) ⇒ ClientRequest

USERLOGIN Version: Username: Password-Length: TimeZone-Length: 0

<data> password

Returns:


196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
# File 'lib/rex/proto/nuuo/client.rb', line 196

def request_userlogin(opts={})
  opts = self.config.merge(opts)
  opts['headers'] ||= {}
  opts['method'] = 'USERLOGIN'

  # Account for version...
  opts['headers']['Version'] = opts['server_version']

  username = nil
  if opts['username'] && opts['username'] != ''
    username = opts['username']
  elsif self.username && self.username != ''
    username = self.username
  end

  opts['headers']['Username'] = username

  password = ''
  if opts['password'] && opts['password'] != ''
    password = opts['password']
  elsif self.password && self.password != ''
    password = self.password
  end
  opts['data'] = password
  opts['headers']['Password-Length'] = password.length

  # Need to verify if this is needed
  opts['headers']['TimeZone-Length'] = '0'

  ClientRequest.new(opts)
end

#send_recv(req, conn = nil, t = -1)) ⇒ Object


73
74
75
76
# File 'lib/rex/proto/nuuo/client.rb', line 73

def send_recv(req, conn=nil, t=-1)
  send_request(req, conn)
  read_response(conn, t)
end

#send_request(req, conn = nil) ⇒ Object


78
79
80
# File 'lib/rex/proto/nuuo/client.rb', line 78

def send_request(req, conn=nil)
  conn ? conn.put(req.to_s) : connect.put(req.to_s)
end

#user_session_header(opts) ⇒ Object


111
112
113
114
115
116
117
118
# File 'lib/rex/proto/nuuo/client.rb', line 111

def user_session_header(opts)
  val = nil
  if opts['user_session']
    val = opts['user_session']
  elsif self.user_session
    val = self.user_session
  end
end