Module: Rex::Post::Meterpreter::HttpPacketDispatcher

Defined in:
lib/rex/post/meterpreter/packet_dispatcher.rb

Instance Method Summary collapse

Instance Method Details

#initialize_passive_dispatcherObject


628
629
630
631
632
633
634
635
636
637
638
639
# File 'lib/rex/post/meterpreter/packet_dispatcher.rb', line 628

def initialize_passive_dispatcher
  super

  # Ensure that there is only one leading and trailing slash on the URI
  resource_uri = "/" + self.conn_id.to_s.gsub(/(^\/|\/$)/, '') + "/"
  self.passive_service = self.passive_dispatcher
  self.passive_service.remove_resource(resource_uri)
  self.passive_service.add_resource(resource_uri,
    'Proc'             => Proc.new { |cli, req| on_passive_request(cli, req) },
    'VirtualDirectory' => true
  )
end

#on_passive_request(cli, req) ⇒ Object


655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
# File 'lib/rex/post/meterpreter/packet_dispatcher.rb', line 655

def on_passive_request(cli, req)

  begin

  resp = Rex::Proto::Http::Response.new(200, "OK")
  resp['Content-Type'] = 'application/octet-stream'
  resp['Connection']   = 'close'

  self.last_checkin = Time.now

  if req.method == 'GET'
    rpkt = send_queue.shift
    resp.body = rpkt || ''
    begin
      cli.send_response(resp)
    rescue ::Exception => e
      send_queue.unshift(rpkt) if rpkt
      elog("Exception sending a reply to the reader request #{cli.inspect}", error: e)
    end
  else
    resp.body = ""
    if req.body and req.body.length > 0
      packet = Packet.new(0)
      packet.add_raw(req.body)
      packet.parse_header!
      packet = decrypt_inbound_packet(packet)
      dispatch_inbound_packet(packet)
    end
    cli.send_response(resp)
  end

  rescue ::Exception => e
    elog("Exception handling request: #{cli.inspect} #{req.inspect}", error: e)
  end
end

#shutdown_passive_dispatcherObject


641
642
643
644
645
646
647
648
649
650
651
652
653
# File 'lib/rex/post/meterpreter/packet_dispatcher.rb', line 641

def shutdown_passive_dispatcher
  if self.passive_service
    # Ensure that there is only one leading and trailing slash on the URI
    resource_uri = "/" + self.conn_id.to_s.gsub(/(^\/|\/$)/, '') + "/"
    self.passive_service.remove_resource(resource_uri) if self.passive_service

    if self.passive_service.resources.empty?
      Rex::ServiceManager.stop_service(self.passive_service)
    end
    self.passive_service = nil
  end
  super
end