@@ -26,7 +26,7 @@ def initialize(info={})
26
26
[
27
27
OptString . new ( 'SUBNET' , [ false , 'Subnet (IPv4, for example, 10.10.10.0)' , nil ] ) ,
28
28
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' ] ] )
30
30
] , self . class )
31
31
end
32
32
@@ -58,6 +58,8 @@ def run
58
58
print_status ( "Adding a route to %s/%s..." % [ datastore [ 'SUBNET' ] , netmask ] )
59
59
add_route ( :subnet => datastore [ 'SUBNET' ] , :netmask => netmask )
60
60
end
61
+ when :autoadd
62
+ autoadd_routes
61
63
when :delete
62
64
if datastore [ 'SUBNET' ]
63
65
print_status ( "Deleting route to %s/%s..." % [ datastore [ 'SUBNET' ] , netmask ] )
@@ -156,6 +158,33 @@ def delete_route(opts={})
156
158
Rex ::Socket ::SwitchBoard . remove_route ( subnet , netmask , session )
157
159
end
158
160
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
159
188
160
189
# Validates the command options
161
190
def validate_cmd ( subnet = nil , netmask = nil )
0 commit comments