Don't distinguish between IPv4 and IPv6 routes

It's easier to deal with one Array of all routes regardless of INET
family than having get_routes() return a two-element Array of Arrays.
Also fixes a bug in each_route() which was expecting get_routes() to
return a single Array of all routes. Thanks to valsmith for reporting.
James Lee 2012-03-02 18:26:57 -07:00
parent c44c0ebf48
commit 9f05562a18
4 changed files with 53 additions and 54 deletions

View File

@ -108,15 +108,15 @@ DWORD request_net_config_get_routes(Remote *remote, Packet *packet)
for(index = 0; index < table_ipv6->entries; index++) {
Tlv route6[5];
route6[0].header.type = TLV_TYPE_SUBNET6;
route6[0].header.type = TLV_TYPE_SUBNET;
route6[0].header.length = sizeof(__u128);
route6[0].buffer = (PUCHAR)&table_ipv6->routes[index].dest6;
route6[1].header.type = TLV_TYPE_NETMASK6;
route6[1].header.type = TLV_TYPE_NETMASK;
route6[1].header.length = sizeof(__u128);
route6[1].buffer = (PUCHAR)&table_ipv6->routes[index].netmask6;
route6[2].header.type = TLV_TYPE_GATEWAY6;
route6[2].header.type = TLV_TYPE_GATEWAY;
route6[2].header.length = sizeof(__u128);
route6[2].buffer = (PUCHAR)&table_ipv6->routes[index].nexthop6;
@ -129,7 +129,7 @@ DWORD request_net_config_get_routes(Remote *remote, Packet *packet)
route6[4].header.length = sizeof(DWORD);
route6[4].buffer = (PUCHAR)&metric_bigendian;
packet_add_tlv_group(response, TLV_TYPE_NETWORK_ROUTE6, route6, 5);
packet_add_tlv_group(response, TLV_TYPE_NETWORK_ROUTE, route6, 5);
}
dprintf("sent %d IPv6 routes", table_ipv6->entries);

View File

@ -94,11 +94,11 @@ class Config
def get_routes
request = Packet.create_request('stdapi_net_config_get_routes')
routes = []
routes6 = []
response = client.send_request(request)
# Build out the array of routes
# Note: This will include both IPv4 and IPv6 routes
response.each(TLV_TYPE_NETWORK_ROUTE) { |route|
routes << Route.new(
route.get_tlv_value(TLV_TYPE_SUBNET),
@ -108,16 +108,7 @@ class Config
route.get_tlv_value(TLV_TYPE_ROUTE_METRIC))
}
# Build out the array of IPv6 routes
response.each(TLV_TYPE_NETWORK_ROUTE6) { |route6|
routes6 << Route.new(
route6.get_tlv_value(TLV_TYPE_SUBNET6),
route6.get_tlv_value(TLV_TYPE_NETMASK6),
route6.get_tlv_value(TLV_TYPE_GATEWAY6),
route6.get_tlv_value(TLV_TYPE_STRING),
route6.get_tlv_value(TLV_TYPE_ROUTE_METRIC))
}
return routes, routes6
return routes
end
alias routes get_routes

View File

@ -112,50 +112,58 @@ class Console::CommandDispatcher::Stdapi::Net
# Process the commands
case cmd
when "list"
routes,routes6 = client.net.config.routes
routes = client.net.config.routes
if (routes.length == 0)
# IPv4
tbl = Rex::Ui::Text::Table.new(
'Header' => "IPv4 network routes",
'Indent' => 4,
'Columns' =>
[
"Subnet",
"Netmask",
"Gateway",
"Metric",
"Interface"
])
routes.select {|route|
Rex::Socket.is_ipv4?(route.netmask)
}.each { |route|
tbl << [ route.subnet, route.netmask, route.gateway, route.metric, route.interface ]
}
if tbl.rows.length > 0
print("\n" + tbl.to_s + "\n")
else
print_line("No IPv4 routes were found.")
else
tbl = Rex::Ui::Text::Table.new(
'Header' => "IPv4 network routes",
'Indent' => 4,
'Columns' =>
[
"Subnet",
"Netmask",
"Gateway",
"Metric",
"Interface"
])
routes.each { |route|
tbl << [ route.subnet, route.netmask, route.gateway, route.metric, route.interface ]
}
print("\n" + tbl.to_s + "\n")
end
if (routes6.length == 0)
# IPv6
tbl = Rex::Ui::Text::Table.new(
'Header' => "IPv6 network routes",
'Indent' => 4,
'Columns' =>
[
"Subnet",
"Netmask",
"Gateway",
"Metric",
"Interface"
])
routes.select {|route|
Rex::Socket.is_ipv6?(route.netmask)
}.each { |route|
tbl << [ route.subnet, route.netmask, route.gateway, route.metric, route.interface ]
}
if tbl.rows.length > 0
print("\n" + tbl.to_s + "\n")
else
print_line("No IPv6 routes were found.")
else
tbl = Rex::Ui::Text::Table.new(
'Header' => "IPv6 network routes",
'Indent' => 4,
'Columns' =>
[
"Subnet",
"Netmask",
"Gateway",
"Metric",
"Interface"
])
routes6.each { |route6|
tbl << [ route6.subnet, route6.netmask, route6.gateway, route6.metric, route6.interface ]
}
print("\n" + tbl.to_s + "\n")
end
when "add"
# Satisfy check to see that formatting is correct
unless Rex::Socket::RangeWalker.new(args[0]).length == 1