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

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

Instance Method Summary collapse

Instance Method Details

#initialize_passive_dispatcherObject



713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
# File 'lib/rex/post/meterpreter/packet_dispatcher.rb', line 713

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
  )

  # Add a reference count to the handler
  self.passive_service.ref
end

#on_passive_request(cli, req) ⇒ Object



741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
# File 'lib/rex/post/meterpreter/packet_dispatcher.rb', line 741

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



729
730
731
732
733
734
735
736
737
738
739
# File 'lib/rex/post/meterpreter/packet_dispatcher.rb', line 729

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

    self.passive_service.deref
    self.passive_service = nil
  end
  super
end