Skip to content

Commit c5391c2

Browse files
sn0wfa11Brent Cook
authored andcommitted
Update cmd print to match core.rb
1 parent bb815c0 commit c5391c2

File tree

1 file changed

+53
-20
lines changed

1 file changed

+53
-20
lines changed

modules/post/multi/manage/autoroute.rb

Lines changed: 53 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -103,37 +103,70 @@ def delete_all_routes
103103
end
104104
end
105105

106+
# Print all of the active routes defined on the framework
107+
#
106108
# Identical functionality to command_dispatcher/core.rb, and
107109
# nearly identical code
110+
#
111+
# @return [void] A useful return value is not expected here
108112
def print_routes
109-
if Rex::Socket::SwitchBoard.routes.size > 0
110-
tbl = Msf::Ui::Console::Table.new(
111-
Msf::Ui::Console::Table::Style::Default,
112-
'Header' => "Active Routing Table",
113-
'Prefix' => "\n",
114-
'Postfix' => "\n",
115-
'Columns' => [
113+
# IPv4 Table
114+
tbl_ipv4 = Msf::Ui::Console::Table.new(
115+
Msf::Ui::Console::Table::Style::Default,
116+
'Header' => "IPv4 Active Routing Table",
117+
'Prefix' => "\n",
118+
'Postfix' => "\n",
119+
'Columns' =>
120+
[
116121
'Subnet',
117122
'Netmask',
118123
'Gateway',
119124
],
120-
'ColProps' => {
125+
'ColProps' =>
126+
{
121127
'Subnet' => { 'MaxWidth' => 17 },
122128
'Netmask' => { 'MaxWidth' => 17 },
123129
})
124-
ret = []
125130

126-
Rex::Socket::SwitchBoard.each { |route|
127-
if (route.comm.kind_of?(Msf::Session))
128-
gw = "Session #{route.comm.sid}"
129-
else
130-
gw = route.comm.name.split(/::/)[-1]
131-
end
132-
tbl << [ route.subnet, route.netmask, gw ]
133-
}
134-
print_line tbl.to_s
135-
else
136-
print_status "No routes have been added yet"
131+
# IPv6 Table
132+
tbl_ipv6 = Msf::Ui::Console::Table.new(
133+
Msf::Ui::Console::Table::Style::Default,
134+
'Header' => "IPv6 Active Routing Table",
135+
'Prefix' => "\n",
136+
'Postfix' => "\n",
137+
'Columns' =>
138+
[
139+
'Subnet',
140+
'Netmask',
141+
'Gateway',
142+
],
143+
'ColProps' =>
144+
{
145+
'Subnet' => { 'MaxWidth' => 17 },
146+
'Netmask' => { 'MaxWidth' => 17 },
147+
})
148+
149+
# Populate Route Tables
150+
Rex::Socket::SwitchBoard.each { |route|
151+
if (route.comm.kind_of?(Msf::Session))
152+
gw = "Session #{route.comm.sid}"
153+
else
154+
gw = route.comm.name.split(/::/)[-1]
155+
end
156+
157+
tbl_ipv4 << [ route.subnet, route.netmask, gw ] if Rex::Socket.is_ipv4?(route.netmask)
158+
tbl_ipv6 << [ route.subnet, route.netmask, gw ] if Rex::Socket.is_ipv6?(route.netmask)
159+
}
160+
161+
# Print Route Tables
162+
print(tbl_ipv4.to_s) if tbl_ipv4.rows.length > 0
163+
print(tbl_ipv6.to_s) if tbl_ipv6.rows.length > 0
164+
if (tbl_ipv4.rows.length + tbl_ipv6.rows.length) < 1
165+
print_status("There are currently no routes defined.")
166+
elsif (tbl_ipv4.rows.length < 1) && (tbl_ipv6.rows.length > 0)
167+
print_status("There are currently no IPv4 routes defined.")
168+
elsif (tbl_ipv4.rows.length > 0) && (tbl_ipv6.rows.length < 1)
169+
print_status("There are currently no IPv6 routes defined.")
137170
end
138171
end
139172

0 commit comments

Comments
 (0)