Class: Rex::Proto::Nuuo::Client
- Inherits:
-
Object
- Object
- Rex::Proto::Nuuo::Client
- Defined in:
- lib/rex/proto/nuuo/client.rb
Overview
This class is a representation of a nuuo client
Instance Attribute Summary collapse
-
#config ⇒ Hash
ClientRequest configuration options.
-
#connection ⇒ IO
The connection established through Rex sockets.
-
#context ⇒ Hash
The Msf context where the connection belongs to.
-
#host ⇒ String
The nuuo server host.
-
#ncs_version ⇒ String
NCS version used in session.
-
#password ⇒ String
Password for NCS user.
-
#port ⇒ Integer
The nuuo server port.
-
#timeout ⇒ Integer
The connect/read timeout.
-
#user_session ⇒ String
ID for the user session.
-
#username ⇒ String
Username for NCS.
Instance Method Summary collapse
-
#close ⇒ Object
Closes the connection.
-
#connect(temp: false) ⇒ Rex::Socket::Tcp
Creates a connection through a Rex socket.
-
#initialize(opts = {}) ⇒ Client
constructor
A new instance of Client.
- #read_response(conn = nil, t = -1)) ⇒ Object
-
#request_commitconfig(opts = {}) ⇒ ClientRequest
COMMITCONFIG FileName: FileType: 1 Content-Length User-Session-No: <session-no>.
-
#request_getconfig(opts = {}) ⇒ ClientRequest
GETCONFIG FileName: FileType: 1 User-Session-No: <session-no>.
-
#request_getopenalarm(opts = {}) ⇒ ClientRequest
GETOPENALARM NUCM/1.0 DeviceID: <number> SourceServer: <server-id> LastOne: <number>.
- #request_ping(opts = {}) ⇒ Object
- #request_sendlicfile(opts = {}) ⇒ Object
-
#request_userlogin(opts = {}) ⇒ ClientRequest
USERLOGIN Version: Username: Password-Length: TimeZone-Length: 0.
- #send_recv(req, conn = nil, t = -1)) ⇒ Object
- #send_request(req, conn = nil) ⇒ Object
- #user_session_header(opts) ⇒ Object
Constructor Details
#initialize(opts = {}) ⇒ Client
Returns a new instance of Client.
41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/rex/proto/nuuo/client.rb', line 41 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
#config ⇒ Hash
Returns ClientRequest configuration options.
39 40 41 |
# File 'lib/rex/proto/nuuo/client.rb', line 39 def config @config end |
#connection ⇒ IO
Returns The connection established through Rex sockets.
21 22 23 |
# File 'lib/rex/proto/nuuo/client.rb', line 21 def connection @connection end |
#context ⇒ Hash
Returns The Msf context where the connection belongs to.
24 25 26 |
# File 'lib/rex/proto/nuuo/client.rb', line 24 def context @context end |
#host ⇒ String
Returns The nuuo server host.
12 13 14 |
# File 'lib/rex/proto/nuuo/client.rb', line 12 def host @host end |
#ncs_version ⇒ String
Returns NCS version used in session.
27 28 29 |
# File 'lib/rex/proto/nuuo/client.rb', line 27 def ncs_version @ncs_version end |
#password ⇒ String
Returns Password for NCS user.
33 34 35 |
# File 'lib/rex/proto/nuuo/client.rb', line 33 def password @password end |
#port ⇒ Integer
Returns The nuuo server port.
15 16 17 |
# File 'lib/rex/proto/nuuo/client.rb', line 15 def port @port end |
#timeout ⇒ Integer
Returns The connect/read timeout.
18 19 20 |
# File 'lib/rex/proto/nuuo/client.rb', line 18 def timeout @timeout end |
#user_session ⇒ String
Returns ID for the user session.
36 37 38 |
# File 'lib/rex/proto/nuuo/client.rb', line 36 def user_session @user_session end |
#username ⇒ String
Returns Username for NCS.
30 31 32 |
# File 'lib/rex/proto/nuuo/client.rb', line 30 def username @username end |
Instance Method Details
#close ⇒ Object
Closes the connection
62 63 64 65 66 67 68 69 |
# File 'lib/rex/proto/nuuo/client.rb', line 62 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
56 57 58 59 |
# File 'lib/rex/proto/nuuo/client.rb', line 56 def connect(temp: false) return connection if connection && !temp return create_tcp_connection(temp: temp) end |
#read_response(conn = nil, t = -1)) ⇒ Object
80 81 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 |
# File 'lib/rex/proto/nuuo/client.rb', line 80 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
169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 |
# File 'lib/rex/proto/nuuo/client.rb', line 169 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>
148 149 150 151 152 153 154 155 156 157 158 159 |
# File 'lib/rex/proto/nuuo/client.rb', line 148 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>
231 232 233 234 235 236 237 238 239 240 241 |
# File 'lib/rex/proto/nuuo/client.rb', line 231 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
118 119 120 121 122 123 124 125 126 |
# File 'lib/rex/proto/nuuo/client.rb', line 118 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
128 129 130 131 132 133 134 135 136 137 138 139 140 141 |
# File 'lib/rex/proto/nuuo/client.rb', line 128 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
194 195 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 |
# File 'lib/rex/proto/nuuo/client.rb', line 194 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
71 72 73 74 |
# File 'lib/rex/proto/nuuo/client.rb', line 71 def send_recv(req, conn=nil, t=-1) send_request(req, conn) read_response(conn, t) end |
#send_request(req, conn = nil) ⇒ Object
76 77 78 |
# File 'lib/rex/proto/nuuo/client.rb', line 76 def send_request(req, conn=nil) conn ? conn.put(req.to_s) : connect.put(req.to_s) end |
#user_session_header(opts) ⇒ Object
109 110 111 112 113 114 115 116 |
# File 'lib/rex/proto/nuuo/client.rb', line 109 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 |