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.



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

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

Instance Method Details

#add_cable(cable, _unused_call) ⇒ Object



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

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



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

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

#available_addresses(_no_params, _unused_call) ⇒ Object



347
348
349
350
# File 'lib/metasploit/aggregator.rb', line 347

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



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

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

#default(_no_params, _unused_call) ⇒ Object



341
342
343
344
345
# File 'lib/metasploit/aggregator.rb', line 341

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



306
307
308
309
# File 'lib/metasploit/aggregator.rb', line 306

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



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
378
379
380
381
382
383
384
385
386
387
388
# File 'lib/metasploit/aggregator.rb', line 352

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
      break unless uuid.nil?
    end
    while true
      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
      sleep 0.1
      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



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

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



311
312
313
314
# File 'lib/metasploit/aggregator.rb', line 311

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



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

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



316
317
318
319
# File 'lib/metasploit/aggregator.rb', line 316

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



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

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

#version(_no_params, _unused_call) ⇒ Object



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

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