@@ -159,31 +159,43 @@ def delete_route(opts={})
159
159
Rex ::Socket ::SwitchBoard . remove_route ( subnet , netmask , session )
160
160
end
161
161
162
+ def is_routable? ( route )
163
+ if route . subnet =~ /^224\. |127\. /
164
+ return false
165
+ elsif route . subnet =~ /[\d \. ]+\. 0$/
166
+ return false
167
+ elsif route . subnet == '0.0.0.0'
168
+ return false
169
+ elsif route . subnet == '255.255.255.255'
170
+ return false
171
+ end
172
+
173
+ true
174
+ end
175
+
162
176
# This function will search for valid subnets on the target and attempt
163
177
# add a route to each. (Operation from auto_add_route plugin.)
164
178
#
165
179
# @return [void] A useful return value is not expected here
166
180
def autoadd_routes
167
181
switch_board = Rex ::Socket ::SwitchBoard . instance
168
- print_status ( "Searcing for subnets to autoroute." )
182
+ print_status ( "Searching for subnets to autoroute." )
169
183
found = false
170
184
171
185
session . net . config . each_route do | route |
172
- # Remove multicast and loopback interfaces
173
- next if route . subnet =~ /^(224\. |127\. )/
174
- next if route . subnet == '0.0.0.0'
175
- next if route . netmask == '255.255.255.255'
186
+ next unless is_routable? ( route )
176
187
177
188
if !switch_board . route_exists? ( route . subnet , route . netmask )
178
189
begin
179
- if Rex ::Socket ::SwitchBoard . add_route ( route . subnet , route . netmask , session )
180
- print_good ( "Route added to subnet #{ route . subnet } /#{ route . netmask } " )
190
+ netmask = route . netmask == '255.255.255.255' ? '255.255.255.0' : route . netmask
191
+ if Rex ::Socket ::SwitchBoard . add_route ( route . subnet , netmask , session )
192
+ print_good ( "Route added to subnet #{ route . subnet } /#{ netmask } " )
181
193
found = true
182
194
else
183
- print_error ( "Could not add route to subnet #{ route . subnet } /#{ route . netmask } " )
195
+ print_error ( "Could not add route to subnet #{ route . subnet } /#{ netmask } " )
184
196
end
185
197
rescue ::Rex ::Post ::Meterpreter ::RequestError => error
186
- print_error ( "Could not add route to subnet #{ route . subnet } /(#{ route . netmask } )" )
198
+ print_error ( "Could not add route to subnet #{ route . subnet } /(#{ netmask } )" )
187
199
print_error ( error . to_s )
188
200
end
189
201
end
0 commit comments