Module: Msf::Handler::Reverse::Comm

Included in:
Msf::Handler::ReverseTcp, Msf::Handler::ReverseTcpDouble, Msf::Handler::ReverseTcpDoubleSSL
Defined in:
lib/msf/core/handler/reverse/comm.rb

Overview

Implements the reverse Rex::Socket::Comm handlng.

Instance Method Summary collapse

Instance Method Details

#initialize(info = {}) ⇒ Object


15
16
17
18
19
20
21
22
# File 'lib/msf/core/handler/reverse/comm.rb', line 15

def initialize(info = {})
  super

  register_advanced_options(
    [
      OptString.new('ReverseListenerComm', [ false, 'The specific communication channel to use for this listener']),
    ], Msf::Handler::Reverse::Comm)
end

#select_commObject


24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/msf/core/handler/reverse/comm.rb', line 24

def select_comm
  rl_comm = datastore['ReverseListenerComm'].to_s
  case rl_comm
  when 'local'
    comm = ::Rex::Socket::Comm::Local
  when /\A[0-9]+\Z/
    comm = framework.sessions[rl_comm.to_i]
    raise(RuntimeError, "Reverse Listener Comm (Session #{rl_comm}) does not exist") unless comm
    raise(RuntimeError, "Reverse Listener Comm (Session #{rl_comm}) does not implement Rex::Socket::Comm") unless comm.is_a? ::Rex::Socket::Comm
  when nil, ''
    comm = nil
  else
    raise(RuntimeError, "Reverse Listener Comm '#{rl_comm}' is invalid")
  end

  comm
end

#via_string_for_ip(ip, comm) ⇒ Object


42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/msf/core/handler/reverse/comm.rb', line 42

def via_string_for_ip(ip, comm)
  comm_used = comm
  comm_used ||= Rex::Socket::SwitchBoard.best_comm(ip)
  comm_used ||= Rex::Socket::Comm::Local

  if comm_used.respond_to?(:type) && comm_used.respond_to?(:sid)
    via = "via the #{comm_used.type} on session #{comm_used.sid}"
  else
    via = ""
  end

  via
end