Skip to content

Commit c4f1e0d

Browse files
committed
Land rapid7#7913, Fix Console Route Print with ipv4 and ipv6
2 parents 2c570b6 + 02afc3a commit c4f1e0d

File tree

1 file changed

+35
-7
lines changed
  • lib/msf/ui/console/command_dispatcher

1 file changed

+35
-7
lines changed

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

Lines changed: 35 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -890,9 +890,10 @@ def cmd_route(*args)
890890
Rex::Socket::SwitchBoard.flush_routes
891891

892892
when "print"
893-
tbl = Table.new(
893+
# IPv4 Table
894+
tbl_ipv4 = Table.new(
894895
Table::Style::Default,
895-
'Header' => "Active Routing Table",
896+
'Header' => "IPv4 Active Routing Table",
896897
'Prefix' => "\n",
897898
'Postfix' => "\n",
898899
'Columns' =>
@@ -907,21 +908,48 @@ def cmd_route(*args)
907908
'Netmask' => { 'MaxWidth' => 17 },
908909
})
909910

911+
# IPv6 Table
912+
tbl_ipv6 = Table.new(
913+
Table::Style::Default,
914+
'Header' => "IPv6 Active Routing Table",
915+
'Prefix' => "\n",
916+
'Postfix' => "\n",
917+
'Columns' =>
918+
[
919+
'Subnet',
920+
'Netmask',
921+
'Gateway',
922+
],
923+
'ColProps' =>
924+
{
925+
'Subnet' => { 'MaxWidth' => 17 },
926+
'Netmask' => { 'MaxWidth' => 17 },
927+
})
928+
929+
# Populate Route Tables
910930
Rex::Socket::SwitchBoard.each { |route|
911931
if (route.comm.kind_of?(Msf::Session))
912932
gw = "Session #{route.comm.sid}"
913933
else
914934
gw = route.comm.name.split(/::/)[-1]
915935
end
916936

917-
tbl << [ route.subnet, route.netmask, gw ]
937+
tbl_ipv4 << [ route.subnet, route.netmask, gw ] if Rex::Socket.is_ipv4?(route.netmask)
938+
tbl_ipv6 << [ route.subnet, route.netmask, gw ] if Rex::Socket.is_ipv6?(route.netmask)
918939
}
919940

920-
if tbl.rows.length == 0
921-
print_status('There are currently no routes defined.')
922-
else
923-
print(tbl.to_s)
941+
# Print Route Tables
942+
print(tbl_ipv4.to_s) if tbl_ipv4.rows.length > 0
943+
print(tbl_ipv6.to_s) if tbl_ipv6.rows.length > 0
944+
945+
if (tbl_ipv4.rows.length + tbl_ipv6.rows.length) < 1
946+
print_status("There are currently no routes defined.")
947+
elsif (tbl_ipv4.rows.length < 1) && (tbl_ipv6.rows.length > 0)
948+
print_status("There are currently no IPv4 routes defined.")
949+
elsif (tbl_ipv4.rows.length > 0) && (tbl_ipv6.rows.length < 1)
950+
print_status("There are currently no IPv6 routes defined.")
924951
end
952+
925953
else
926954
cmd_route_help
927955
end

0 commit comments

Comments
 (0)