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.



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

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

Instance Method Details

#add_cable(cable, _unused_call) ⇒ Object



317
318
319
320
321
322
# File 'lib/metasploit/aggregator.rb', line 317

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



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

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

#available_addresses(_no_params, _unused_call) ⇒ Object



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

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



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

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

#default(_no_params, _unused_call) ⇒ Object



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

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



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

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



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
378
379
380
381
382
383
# File 'lib/metasploit/aggregator.rb', line 348

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
      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



330
331
332
333
334
335
# File 'lib/metasploit/aggregator.rb', line 330

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



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

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



324
325
326
327
328
# File 'lib/metasploit/aggregator.rb', line 324

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



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

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



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

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

#version(_no_params, _unused_call) ⇒ Object



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

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