Skip to content

Commit fda5faf

Browse files
committed
Land rapid7#7346, route command fixes
Also adds session -1 support.
2 parents 1362bc9 + a3e3bbf commit fda5faf

File tree

1 file changed

+13
-14
lines changed
  • lib/msf/ui/console/command_dispatcher

1 file changed

+13
-14
lines changed

lib/msf/ui/console/command_dispatcher/core.rb

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1327,24 +1327,20 @@ def cmd_route_help
13271327
# which session a given subnet should route through.
13281328
#
13291329
def cmd_route(*args)
1330-
if (args.length == 0)
1331-
cmd_route_help
1332-
return false
1333-
end
1330+
args << 'print' if args.length == 0
13341331

13351332
action = args.shift
13361333
case action
13371334

13381335
when "add", "remove", "del"
13391336
subnet = args.shift
1340-
subnet,cidr_mask = subnet.split("/")
1341-
1342-
if cidr_mask
1343-
netmask = Rex::Socket.addr_ctoa(cidr_mask.to_i)
1344-
else
1345-
netmask = args.shift
1337+
netmask = nil
1338+
if subnet
1339+
subnet, cidr_mask = subnet.split("/")
1340+
netmask = Rex::Socket.addr_ctoa(cidr_mask.to_i) if cidr_mask
13461341
end
13471342

1343+
netmask = args.shift if netmask.nil?
13481344
gateway_name = args.shift
13491345

13501346
if (subnet.nil? || netmask.nil? || gateway_name.nil?)
@@ -1357,15 +1353,15 @@ def cmd_route(*args)
13571353
case gateway_name
13581354
when /local/i
13591355
gateway = Rex::Socket::Comm::Local
1360-
when /^[0-9]+$/
1356+
when /^(-1|[0-9]+)$/
13611357
session = framework.sessions.get(gateway_name)
13621358
if session.kind_of?(Msf::Session::Comm)
13631359
gateway = session
13641360
elsif session.nil?
13651361
print_error("Not a session: #{gateway_name}")
13661362
return false
13671363
else
1368-
print_error("Cannout route through specified session (not a Comm)")
1364+
print_error("Cannot route through the specified session (not a Comm)")
13691365
return false
13701366
end
13711367
else
@@ -1421,7 +1417,6 @@ def cmd_route(*args)
14211417
})
14221418

14231419
Rex::Socket::SwitchBoard.each { |route|
1424-
14251420
if (route.comm.kind_of?(Msf::Session))
14261421
gw = "Session #{route.comm.sid}"
14271422
else
@@ -1431,7 +1426,11 @@ def cmd_route(*args)
14311426
tbl << [ route.subnet, route.netmask, gw ]
14321427
}
14331428

1434-
print(tbl.to_s)
1429+
if tbl.rows.length == 0
1430+
print_status('There are currently no routes defined.')
1431+
else
1432+
print(tbl.to_s)
1433+
end
14351434
else
14361435
cmd_route_help
14371436
end

0 commit comments

Comments
 (0)