Class: Msf::Exploit::Remote::HTTP::Beyondtrust::RemoteSupport::MrsClient
- Inherits:
-
Object
- Object
- Msf::Exploit::Remote::HTTP::Beyondtrust::RemoteSupport::MrsClient
- Defined in:
- lib/msf/core/exploit/remote/http/beyondtrust/remote_support.rb
Overview
Native message-router client with multiplexed stream mailboxes.
Constant Summary collapse
- GREETING =
'hello Mrs. Router'
Instance Attribute Summary collapse
-
#listener ⇒ Object
readonly
Returns the value of attribute listener.
-
#node ⇒ Object
readonly
Returns the value of attribute node.
-
#properties ⇒ Object
readonly
Returns the value of attribute properties.
-
#router ⇒ Object
readonly
Returns the value of attribute router.
Class Method Summary collapse
-
.parse_address(address) ⇒ Array<Integer>
Validated address components.
Instance Method Summary collapse
-
#accept_stream(listener) ⇒ MrsStream
Established stream.
-
#address(handler) ⇒ String
Native address.
-
#allocate_handler ⇒ Integer
Unused mailbox identifier.
-
#connect_stream(destination) ⇒ MrsStream
Established stream.
-
#initialize(wire) ⇒ MrsClient
constructor
A new instance of MrsClient.
-
#receive(handler) ⇒ Hash
Message header and payload.
- #send_message(destination, payload, source_router: nil, flags: 1) ⇒ void
Constructor Details
#initialize(wire) ⇒ MrsClient
Returns a new instance of MrsClient.
157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 |
# File 'lib/msf/core/exploit/remote/http/beyondtrust/remote_support.rb', line 157 def initialize(wire) @wire = wire @pending = Hash.new { |hash, key| hash[key] = [] } @next_handler = 1024 @properties = Fields.decode(wire.line) @listener = wire.line wire.line # Server-advertised handshake timeout. raise ProtocolError, 'Invalid MRS greeting' unless wire.line == GREETING wire.write("#{GREETING}\n") @node = integer(wire.line) wire.write("#{node}\n") integer(wire.line) # The brain router is not the customer's identity. @router = SecureRandom.random_number(0x7ffff000) + 1024 wire.write("#{router}\n") wire.write("#{wire.line}\n") raise ProtocolError, 'Invalid MRS acknowledgement' unless wire.read(1) == '1' wire.write('1') end |
Instance Attribute Details
#listener ⇒ Object (readonly)
Returns the value of attribute listener.
154 155 156 |
# File 'lib/msf/core/exploit/remote/http/beyondtrust/remote_support.rb', line 154 def listener @listener end |
#node ⇒ Object (readonly)
Returns the value of attribute node.
154 155 156 |
# File 'lib/msf/core/exploit/remote/http/beyondtrust/remote_support.rb', line 154 def node @node end |
#properties ⇒ Object (readonly)
Returns the value of attribute properties.
154 155 156 |
# File 'lib/msf/core/exploit/remote/http/beyondtrust/remote_support.rb', line 154 def properties @properties end |
#router ⇒ Object (readonly)
Returns the value of attribute router.
154 155 156 |
# File 'lib/msf/core/exploit/remote/http/beyondtrust/remote_support.rb', line 154 def router @router end |
Class Method Details
.parse_address(address) ⇒ Array<Integer>
Returns validated address components.
227 228 229 230 231 232 233 234 |
# File 'lib/msf/core/exploit/remote/http/beyondtrust/remote_support.rb', line 227 def self.parse_address(address) parts = address.is_a?(Array) ? address : address.to_s.split(':') unless parts.length == 3 && parts.all? { |part| part.to_s.match?(/\A\d+\z/) && part.to_i.between?(0, 0xffffffff) } raise ProtocolError, 'Invalid MRS address' end parts.map(&:to_i) end |
Instance Method Details
#accept_stream(listener) ⇒ MrsStream
Returns established stream.
253 254 255 256 257 258 259 260 261 |
# File 'lib/msf/core/exploit/remote/http/beyondtrust/remote_support.rb', line 253 def accept_stream(listener) request = receive(listener)[:payload].split('|', 3) raise ProtocolError, 'Invalid MRS stream connection request' unless request.length == 3 && request.first == 'connect' self.class.parse_address(request.last) handler = allocate_handler (request.last, "accepted|#{address(handler)}") MrsStream.new(self, handler, request.last) end |
#address(handler) ⇒ String
Returns native address.
180 181 182 |
# File 'lib/msf/core/exploit/remote/http/beyondtrust/remote_support.rb', line 180 def address(handler) "#{node}:#{router}:#{handler}" end |
#allocate_handler ⇒ Integer
Returns unused mailbox identifier.
185 186 187 |
# File 'lib/msf/core/exploit/remote/http/beyondtrust/remote_support.rb', line 185 def allocate_handler @next_handler += 1 end |
#connect_stream(destination) ⇒ MrsStream
Returns established stream.
238 239 240 241 242 243 244 245 246 247 248 249 |
# File 'lib/msf/core/exploit/remote/http/beyondtrust/remote_support.rb', line 238 def connect_stream(destination) handler = allocate_handler # This identifies a connection attempt; it is not an authentication secret. (destination, "connect|#{rand(10_000_000)}|#{address(handler)}") response = receive(handler)[:payload] raise ProtocolError, 'MRS stream connection was rejected' unless response.start_with?('accepted|') remote = response.split('|', 2).last self.class.parse_address(remote) (destination, "accepted acknowledged|#{address(handler)}") MrsStream.new(self, handler, remote) end |
#receive(handler) ⇒ Hash
Returns message header and payload.
204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 |
# File 'lib/msf/core/exploit/remote/http/beyondtrust/remote_support.rb', line 204 def receive(handler) return @pending[handler].shift unless @pending[handler].empty? loop do header = @wire.read(HEADER_SIZE).unpack('V9') raise ProtocolError, 'Invalid MRS message length' unless header.first.between?(HEADER_SIZE, MAX_MESSAGE) payload = @wire.read(header.first - HEADER_SIZE) if header[5] == 1 && payload == 'PING' ([header[1], header[2], 1], 'PONG') next end = { header: header, payload: payload } return if header[5] == handler raise ProtocolError, 'Excessive pending MRS messages' if @pending.values.sum(&:length) >= 512 @pending[header[5]] << end end |
#send_message(destination, payload, source_router: nil, flags: 1) ⇒ void
This method returns an undefined value.
194 195 196 197 198 199 200 |
# File 'lib/msf/core/exploit/remote/http/beyondtrust/remote_support.rb', line 194 def (destination, payload, source_router: nil, flags: 1) destination = self.class.parse_address(destination) header = [HEADER_SIZE + payload.bytesize, node, source_router || router, *destination, 0, flags, 5] raise ProtocolError, 'Oversized outgoing MRS message' if header.first > MAX_MESSAGE @wire.write(header.pack('V9') + payload.b) end |