Class: Metasploit::Aggregator::ServerImpl

Inherits:
Pb::Service
  • Object
show all
Defined in:
lib/metasploit/aggregator.rb

Instance Method Summary collapse

Constructor Details

#initializeServerImpl

Returns a new instance of ServerImpl.



275
276
277
278
279
280
# File 'lib/metasploit/aggregator.rb', line 275

def initialize
  super
  @local_server = Server.new
  @requestThreads = {}
  @listeners = []
end

Instance Method Details

#add_cable(cable, _unused_call) ⇒ Object



313
314
315
316
317
318
# File 'lib/metasploit/aggregator.rb', line 313

def add_cable(cable, _unused_call)
  pem = nil
  pem = cable.pem unless cable.pem.empty?
  result = @local_server.add_cable(cable.type, cable.host, cable.port, pem)
  Metasploit::Aggregator::Message::Result.new( answer: result )
end

#available(_no_params, _unused_call) ⇒ Object



282
283
284
# File 'lib/metasploit/aggregator.rb', line 282

def available(_no_params, _unused_call)
  Metasploit::Aggregator::Message::Result.new( answer: @local_server.available? )
end

#available_addresses(_no_params, _unused_call) ⇒ Object



339
340
341
342
# File 'lib/metasploit/aggregator.rb', line 339

def available_addresses(_no_params, _unused_call)
  addresses = @local_server.available_addresses
  Metasploit::Aggregator::Message::String_array.new( value: addresses )
end

#cables(_no_parms, _unused_call) ⇒ Object



294
295
296
# File 'lib/metasploit/aggregator.rb', line 294

def cables(_no_parms, _unused_call)
  Metasploit::Aggregator::Message::String_array.new( value: @local_server.cables() )
end

#default(_no_params, _unused_call) ⇒ Object



333
334
335
336
337
# File 'lib/metasploit/aggregator.rb', line 333

def default(_no_params, _unused_call)
  uuid = @local_server.default
  return Metasploit::Aggregator::Message::String_array.new( value: [ uuid ] ) unless uuid.nil?
  Metasploit::Aggregator::Message::String_array.new()
end

#obtain_session(args, _unused_call) ⇒ Object



298
299
300
301
# File 'lib/metasploit/aggregator.rb', line 298

def obtain_session(args, _unused_call)
  payload, uuid = args.value
  Metasploit::Aggregator::Message::Result.new( answer: @local_server.obtain_session(payload, uuid) )
end

#process(responses) ⇒ Object



344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
# File 'lib/metasploit/aggregator.rb', line 344

def process(responses)
  requests = EnumeratorQueue.new(self)
  uuid = nil

  requestingThread = Thread.new do
    loop do
      sleep 0.1 # outer loop only occurs until uuid is set
      next if uuid.nil?
      request = @local_server.request(uuid)
      # TODO: with this in place we can just get the request queue and pop each item to process and forward
      unless request.nil?
        body = ""
        body = request.body unless request.body.nil?
        pb_request = Metasploit::Aggregator::Message::Request.new( headers: request.headers, body: body )
        requests.push(pb_request)
      end
    end
  end

  Thread.new do
    responses.each do |response|
      uuid = response.uuid if uuid.nil?
      next if response.response.nil?
      request_pb = response.response
      request = Metasploit::Aggregator::Http::Request.new(request_pb.headers, request_pb.body, nil)
      @local_server.respond(response.uuid, request)
    end
    requestingThread.exit
    requestingThread.join
    requests.push(self)
  end

  requests.each_item
end

#register_default(register, _unused_call) ⇒ Object



326
327
328
329
330
331
# File 'lib/metasploit/aggregator.rb', line 326

def register_default(register, _unused_call)
  payloads = nil
  payloads = register.payloads unless register.payloads.empty?
  result = @local_server.register_default(register.uuid, payloads)
  Metasploit::Aggregator::Message::Result.new( answer: result )
end

#release_session(args, _unused_call) ⇒ Object



303
304
305
306
# File 'lib/metasploit/aggregator.rb', line 303

def release_session(args, _unused_call)
  payload = args.value.shift
  Metasploit::Aggregator::Message::Result.new( answer: @local_server.release_session(payload) )
end

#remove_cable(args, _unused_call) ⇒ Object



320
321
322
323
324
# File 'lib/metasploit/aggregator.rb', line 320

def remove_cable(args, _unused_call)
  host, port = args.value
  result = @local_server.remove_cable(host, port)
  Metasploit::Aggregator::Message::Result.new( answer: result )
end

#session_details(args, _unused_call) ⇒ Object



308
309
310
311
# File 'lib/metasploit/aggregator.rb', line 308

def session_details(args, _unused_call)
  payload = args.value.shift
  Metasploit::Aggregator::Message::Result_map.new( map: @local_server.session_details(payload) )
end

#sessions(_no_parms, _unused_call) ⇒ Object



290
291
292
# File 'lib/metasploit/aggregator.rb', line 290

def sessions(_no_parms, _unused_call)
  Metasploit::Aggregator::Message::Result_map.new( map: @local_server.sessions() )
end

#version(_no_params, _unused_call) ⇒ Object



286
287
288
# File 'lib/metasploit/aggregator.rb', line 286

def version(_no_params, _unused_call)
  Metasploit::Aggregator::Message::String_array.new( value: [ @local_server.version ] )
end