CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
rapid7

CoCalc provides the best real-time collaborative environment for Jupyter Notebooks, LaTeX documents, and SageMath, scalable from individual users to large groups and classes!

GitHub Repository: rapid7/metasploit-framework
Path: blob/master/plugins/auto_add_route.rb
Views: 1903
1
module Msf
2
class Plugin::AutoAddRoute < Msf::Plugin
3
include Msf::SessionEvent
4
def name
5
'auto_add_route'
6
end
7
8
def desc
9
'Adds routes for any new subnets whenever a session opens'
10
end
11
12
def on_session_open(session)
13
return if session.type != 'meterpreter'
14
15
session.load_stdapi
16
sb = Rex::Socket::SwitchBoard.instance
17
session.net.config.each_route do |route|
18
# Remove multicast and loopback interfaces
19
next if route.subnet =~ /^(224\.|127\.)/
20
next if route.subnet == '0.0.0.0'
21
next if route.netmask == '255.255.255.255'
22
23
if !sb.route_exists?(route.subnet, route.netmask)
24
print_status("AutoAddRoute: Routing new subnet #{route.subnet}/#{route.netmask} through session #{session.sid}")
25
sb.add_route(route.subnet, route.netmask, session)
26
end
27
end
28
end
29
30
def initialize(framework, opts)
31
super
32
self.framework.events.add_session_subscriber(self)
33
end
34
35
def cleanup
36
framework.events.remove_session_subscriber(self)
37
end
38
39
end
40
end
41
42