@@ -15,7 +15,8 @@ def initialize(info={})
15
15
'Name' => 'Windows Manage Network Route via Meterpreter Session' ,
16
16
'Description' => %q{This module manages session routing via an existing
17
17
Meterpreter session. It enables other modules to 'pivot' through a
18
- compromised host when connecting to the named NETWORK and SUBMASK.} ,
18
+ compromised host when connecting to the named NETWORK and SUBMASK.
19
+ Autoadd will search session for valid subnets and route to them.} ,
19
20
'License' => MSF_LICENSE ,
20
21
'Author' => [ 'todb' ] ,
21
22
'Platform' => [ 'win' ] ,
@@ -26,7 +27,7 @@ def initialize(info={})
26
27
[
27
28
OptString . new ( 'SUBNET' , [ false , 'Subnet (IPv4, for example, 10.10.10.0)' , nil ] ) ,
28
29
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' ] ] )
30
+ OptEnum . new ( 'CMD' , [ true , 'Specify the autoroute command' , 'autoadd ' , [ 'add' , 'autoadd ', 'print' , 'delete' ] ] )
30
31
] , self . class )
31
32
end
32
33
@@ -58,6 +59,8 @@ def run
58
59
print_status ( "Adding a route to %s/%s..." % [ datastore [ 'SUBNET' ] , netmask ] )
59
60
add_route ( :subnet => datastore [ 'SUBNET' ] , :netmask => netmask )
60
61
end
62
+ when :autoadd
63
+ autoadd_routes
61
64
when :delete
62
65
if datastore [ 'SUBNET' ]
63
66
print_status ( "Deleting route to %s/%s..." % [ datastore [ 'SUBNET' ] , netmask ] )
@@ -156,6 +159,49 @@ def delete_route(opts={})
156
159
Rex ::Socket ::SwitchBoard . remove_route ( subnet , netmask , session )
157
160
end
158
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
+
176
+ # This function will search for valid subnets on the target and attempt
177
+ # add a route to each. (Operation from auto_add_route plugin.)
178
+ #
179
+ # @return [void] A useful return value is not expected here
180
+ def autoadd_routes
181
+ switch_board = Rex ::Socket ::SwitchBoard . instance
182
+ print_status ( "Searching for subnets to autoroute." )
183
+ found = false
184
+
185
+ session . net . config . each_route do | route |
186
+ next unless is_routable? ( route )
187
+
188
+ if !switch_board . route_exists? ( route . subnet , route . netmask )
189
+ begin
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 } " )
193
+ found = true
194
+ else
195
+ print_error ( "Could not add route to subnet #{ route . subnet } /#{ netmask } " )
196
+ end
197
+ rescue ::Rex ::Post ::Meterpreter ::RequestError => error
198
+ print_error ( "Could not add route to subnet #{ route . subnet } /(#{ netmask } )" )
199
+ print_error ( error . to_s )
200
+ end
201
+ end
202
+ end
203
+ print_status ( "Did not find any new subnets to add." ) if !found
204
+ end
159
205
160
206
# Validates the command options
161
207
def validate_cmd ( subnet = nil , netmask = nil )
0 commit comments