From 9f05562a18adec5113560e8771786fa75924aa6a Mon Sep 17 00:00:00 2001 From: James Lee Date: Fri, 2 Mar 2012 18:26:57 -0700 Subject: [PATCH] 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. --- data/meterpreter/ext_server_stdapi.lso | Bin 47280 -> 47280 bytes .../stdapi/server/net/config/route.c | 8 +- .../extensions/stdapi/net/config.rb | 13 +-- .../console/command_dispatcher/stdapi/net.rb | 86 ++++++++++-------- 4 files changed, 53 insertions(+), 54 deletions(-) diff --git a/data/meterpreter/ext_server_stdapi.lso b/data/meterpreter/ext_server_stdapi.lso index 149ad8b1cb1ba553ecfee70ac02e88a0995bc530..7e2dfc035d738988566130d0974c819354089059 100755 GIT binary patch delta 77 zcmdn+k!b@Eu`r56ynQuK>T2oV$>~f!g%?s}!!_<*+bqGj-HNei@&#*gv0hddhU2bl h1Q-|?dP6KkIzzV{ciq!B`LA`$klklh8XC7Lf%6 h0LMkF5C8xGjZ`=kiB+`6MZA)e{X2vKle2<6E_|Da9(e!& diff --git a/external/source/meterpreter/source/extensions/stdapi/server/net/config/route.c b/external/source/meterpreter/source/extensions/stdapi/server/net/config/route.c index 2b7d37c5a3..a49b2e2e4f 100644 --- a/external/source/meterpreter/source/extensions/stdapi/server/net/config/route.c +++ b/external/source/meterpreter/source/extensions/stdapi/server/net/config/route.c @@ -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); diff --git a/lib/rex/post/meterpreter/extensions/stdapi/net/config.rb b/lib/rex/post/meterpreter/extensions/stdapi/net/config.rb index f112ef79e4..e8e1fdb08e 100644 --- a/lib/rex/post/meterpreter/extensions/stdapi/net/config.rb +++ b/lib/rex/post/meterpreter/extensions/stdapi/net/config.rb @@ -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 diff --git a/lib/rex/post/meterpreter/ui/console/command_dispatcher/stdapi/net.rb b/lib/rex/post/meterpreter/ui/console/command_dispatcher/stdapi/net.rb index b3e126cc9b..da94a38fd7 100644 --- a/lib/rex/post/meterpreter/ui/console/command_dispatcher/stdapi/net.rb +++ b/lib/rex/post/meterpreter/ui/console/command_dispatcher/stdapi/net.rb @@ -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