Skip to content

Commit 3abb6fe

Browse files
committed
Add autoadd feature to autoroute.rb
1 parent 1828b7f commit 3abb6fe

File tree

1 file changed

+30
-1
lines changed

1 file changed

+30
-1
lines changed

modules/post/windows/manage/autoroute.rb

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ def initialize(info={})
2626
[
2727
OptString.new('SUBNET', [false, 'Subnet (IPv4, for example, 10.10.10.0)', nil]),
2828
OptString.new('NETMASK', [false, 'Netmask (IPv4 as "255.255.255.0" or CIDR as "/24"', '255.255.255.0']),
29-
OptEnum.new('CMD', [true, 'Specify the autoroute command', 'add', ['add','print','delete']])
29+
OptEnum.new('CMD', [true, 'Specify the autoroute command', 'autoadd', ['add','autoadd','print','delete']])
3030
], self.class)
3131
end
3232

@@ -58,6 +58,8 @@ def run
5858
print_status("Adding a route to %s/%s..." % [datastore['SUBNET'],netmask])
5959
add_route(:subnet => datastore['SUBNET'], :netmask => netmask)
6060
end
61+
when :autoadd
62+
autoadd_routes
6163
when :delete
6264
if datastore['SUBNET']
6365
print_status("Deleting route to %s/%s..." % [datastore['SUBNET'],netmask])
@@ -156,6 +158,33 @@ def delete_route(opts={})
156158
Rex::Socket::SwitchBoard.remove_route(subnet, netmask, session)
157159
end
158160

161+
# This function will search for valid subnets on the target and attempt
162+
# add a route to each. (Operation from auto_add_route plugin.)
163+
#
164+
# @return [void] A useful return value is not expected here
165+
def autoadd_routes
166+
switch_board = Rex::Socket::SwitchBoard.instance
167+
print_status("Searcing for subnets to auto route.")
168+
session.net.config.each_route do | route |
169+
# Remove multicast and loopback interfaces
170+
next if route.subnet =~ /^(224\.|127\.)/
171+
next if route.subnet == '0.0.0.0'
172+
next if route.netmask == '255.255.255.255'
173+
174+
if not switch_board.route_exists?(route.subnet, route.netmask)
175+
begin
176+
if Rex::Socket::SwitchBoard.add_route(route.subnet, route.netmask, session)
177+
print_good("Route added to subnet #{route.subnet}/#{route.netmask}")
178+
else
179+
print_error("Could not add route to subnet #{route.subnet}/#{route.netmask}")
180+
end
181+
rescue ::Rex::Post::Meterpreter::RequestError => error
182+
print_error("Could not add route to subnet #{route.subnet}/(#{route.netmask})")
183+
print_error(error.to_s)
184+
end
185+
end
186+
end
187+
end
159188

160189
# Validates the command options
161190
def validate_cmd(subnet=nil,netmask=nil)

0 commit comments

Comments
 (0)