Class: Msf::Plugin::AutoAddRoute

Inherits:
Msf::Plugin show all
Includes:
SessionEvent
Defined in:
plugins/auto_add_route.rb

Instance Attribute Summary

Attributes inherited from Msf::Plugin

#opts

Attributes included from Framework::Offspring

#framework

Instance Method Summary collapse

Methods included from SessionEvent

#on_session_close, #on_session_command, #on_session_download, #on_session_filedelete, #on_session_interact, #on_session_output, #on_session_upload

Methods inherited from Msf::Plugin

#add_console_dispatcher, create, #flush, #input, #output, #print, #print_error, #print_good, #print_line, #print_status, #print_warning, #remove_console_dispatcher

Constructor Details

#initialize(framework, opts) ⇒ AutoAddRoute

Returns a new instance of AutoAddRoute.



30
31
32
33
# File 'plugins/auto_add_route.rb', line 30

def initialize(framework, opts)
  super
  self.framework.events.add_session_subscriber(self)
end

Instance Method Details

#cleanupObject



35
36
37
# File 'plugins/auto_add_route.rb', line 35

def cleanup
  framework.events.remove_session_subscriber(self)
end

#descObject



8
9
10
# File 'plugins/auto_add_route.rb', line 8

def desc
  'Adds routes for any new subnets whenever a session opens'
end

#nameObject



4
5
6
# File 'plugins/auto_add_route.rb', line 4

def name
  'auto_add_route'
end

#on_session_open(session) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'plugins/auto_add_route.rb', line 12

def on_session_open(session)
  return if session.type != 'meterpreter'

  session.load_stdapi
  sb = Rex::Socket::SwitchBoard.instance
  session.net.config.each_route do |route|
    # Remove multicast and loopback interfaces
    next if route.subnet =~ /^(224\.|127\.)/
    next if route.subnet == '0.0.0.0'
    next if route.netmask == '255.255.255.255'

    if !sb.route_exists?(route.subnet, route.netmask)
      print_status("AutoAddRoute: Routing new subnet #{route.subnet}/#{route.netmask} through session #{session.sid}")
      sb.add_route(route.subnet, route.netmask, session)
    end
  end
end