Module: Msf::Handler::FindPort

Includes:
Msf::Handler
Included in:
FindShell, FindTag, FindTty
Defined in:
lib/msf/core/handler/find_port.rb

Overview

This handlers implements port-based findsock handling.

Constant Summary

Constants included from Msf::Handler

Claimed, Unused

Instance Attribute Summary

Attributes included from Msf::Handler

#exploit_config, #parent_payload

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Msf::Handler

#add_handler, #cleanup_handler, #handle_connection, #handler_name, #setup_handler, #start_handler, #stop_handler, #wait_for_session, #wfs_delay

Class Method Details

.general_handler_typeObject

Returns the connection oriented general handler type, in this case 'find'.


26
27
28
# File 'lib/msf/core/handler/find_port.rb', line 26

def self.general_handler_type
  "find"
end

.handler_typeObject

Returns the string representation of the handler type, in this case 'find_port'.


18
19
20
# File 'lib/msf/core/handler/find_port.rb', line 18

def self.handler_type
  return "find_port"
end

Instance Method Details

#handler(sock) ⇒ Object

Check to see if there's a shell on the supplied sock. This check currently only works for shells.


47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/msf/core/handler/find_port.rb', line 47

def handler(sock)
  return if not sock

  _find_prefix(sock)

  # Flush the receive buffer
  sock.get_once(-1, 1)

  # If this is a multi-stage payload, then we just need to blindly
  # transmit the stage and create the session, hoping that it works.
  if (self.payload_type != Msf::Payload::Type::Single)
    handle_connection(sock)
  # Otherwise, check to see if we found a session.  We really need
  # to improve this, as we could create a session when the exploit
  # really didn't succeed.
  else
    create_session(sock)
  end

  return self._handler_return_value
end

#initialize(info = {}) ⇒ Object

Initializes the find port handler and adds the client port option that is required for port-based findsock payloads to function.


34
35
36
37
38
39
40
41
# File 'lib/msf/core/handler/find_port.rb', line 34

def initialize(info = {})
  super

  register_options(
    [
      Opt::CPORT(rand(64000) + 1024),
    ], Msf::Handler::FindPort)
end